Elements In Child Window Are Null
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aidan_Monroe
Posted On:   Friday, March 14, 2003 10:56 AM

I have a web page that needs to open another window as a pop up. This 2nd window needs to update a field on the parent window. This child window is a common window used by many parent windows (or even multiple times on the same parent), so the parent window needs to tell the child window which form & field to update when it is closed. The parent window launches the child window with the following Javascript: function openLovWindow(name, formToUpdate, fieldToUpdate) { var url = "http://127.0.0.1:7001/webApp/Lov.do?name=" + name; var newWin = openCenteredWindow(url, name + 'LOV', '200', '230', ''); // while (newWin.document.forms.length == 0)    More>>

I have a web page that needs to open another window as a pop up. This 2nd window needs to update a field on the parent window. This child window is a common window used by many parent windows (or even multiple times on the same parent), so the parent window needs to tell the child window which form & field to update when it is closed.



The parent window launches the child window with the following Javascript:



			
function openLovWindow(name, formToUpdate, fieldToUpdate)
{

var url = "http://127.0.0.1:7001/webApp/Lov.do?name=" + name;
var newWin = openCenteredWindow(url, name + 'LOV', '200', '230', '');

// while (newWin.document.forms.length == 0)
// {
// Waiting for window and its elements to be created
// }

if (formToUpdate != null && fieldToUpdate != null)
{
newWin.document.forms["hiddenForm"].elements["formToUpdate"].value
= formToUpdate;
newWin.document.forms["hiddenForm"].elements["fieldToUpdate"].value
= fieldToUpdate;
}
}



The problem is that the attempt to set the 2 values in "hiddenForm" result in a Javascript error "document.forms.hiddenForm.elements is null or is not an object" ).



So I put in the loop that is commented out currently in the Javascript. This waits until the form and its elements have been created. Using this loop works fine in MSIE.



However, there are problems when attempting to run the same script (with the loop) on Netscape. The problem is that Netscape locks up (the parent window and the child window).



Has anyone run into a similar situation before? Is there a way to do this so that it is cross-browser compatible? I'm not a Javascript expert by any means so any advice would be appreciated.    <<Less

Re: Elements In Child Window Are Null

Posted By:   Nitesh_Naveen  
Posted On:   Monday, March 17, 2003 03:24 AM

instead of trying to update the form field from child window, why not try calling a method/function on the parent window. Each pages will have their own implementation of the method according to the form fields in it according to the values passed back from the child window as the arguments of the function. That would be the most ideal way of handling common child windows

You can call a function on the parent window from the child like window.opener.myFunc(arg1,arg2)
About | Sitemap | Contact