By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Passing element values from parent window to child popup window and vice-versa

P: 6
Hi,
In my application, I call one popup winodow by using this link..

[HTML]<a href="#" onClick="return showWindow('1','XYZ');">
<img src="images/magnifier.gif" ALT="Chemicals" width=18 height=20 border=0>
</a>[/HTML]

In this showWindow function....
Expand|Select|Wrap|Line Numbers
  1.  
  2.   var newWindow = '';
  3.   var url='jsp/DEPO/Chemicals/ProductConfigTabs.jsp';
  4.  function showWindow(data1, data2)
  5.    {
  6.     if (!window.focus){return true;}
  7.     if (!newWindow.closed && newWindow.location)
  8.     {
  9.         newWindow.location.href = url;
  10.     }
  11.     else
  12.     {  
  13.           newWindow=window.open(url+'?abc=ABC&Id='+data1,'NewWin','toolbar=no,status=yes,width=520,height=440');    
  14.         if (!newWindow.opener) newWindow.opener = self;
  15.         //Set value into Child window element.
  16.         setTimeout("SendToChild('" + data1.toLocaleString() + "','" + data2.toLocaleString() + "')",20);
  17.         if (window.focus){newWindow.focus();}
  18.  
  19.     }
  20.    }
  21.  
  22.    //Pass value to child window..
  23.    function SendToChild(data1,data2)
  24.    {
  25.     //Set Hidden value into child Window
  26.      newWindow.document.getElementById("hiddenDivId1").value=data1;
  27.         newWindow.document.getElementById("hiddenDivId2").value=data2;
  28.    }
//In child window JSP i use this div for storing parent window passed values.

[HTML] <div id='hiddenDivId1'></div>
<div id='hiddenDivId2'></div>
[/HTML]
** But Some time i can access this hidden div of child window and some time not..
Please help me to pass parent window element values to child and vice-versa Or Any other way to pass value,
like what i did with url, by using parameter.. please check is this way correct to pass and get value in request

[HTML]<input type="hidden" name="Id" id="Id" value="<%=request.getParameter('Id')%>">[/HTML]

Please use code tags when posting code - moderator

I dont know what i am doing wrong in it. please help me in this problem.

Thanks,
Gajendra
Jul 20 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Move the declaration of newWindow outside the function to make it a global variable. If you need to reset it, do not use the var keyword.

When trying to set the content in a div, "value" won't work. Use innerHTML instead or create a text node and append it to the div.

To access the parent from the child, use window.opener.
Jul 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.