Click to See Complete Forum and Search --> : How do I execute a function for another window


JSchwarz
04-14-2003, 10:51 AM
I have a main form. In it's header, I have a link to a JavaScript library, like this:


<SCRIPT LANGUAGE='JavaScript' SRC='/ASSIST/ASSIST.nsf/JavaScriptLib.js/'></SCRIPT>


JavaScriptLib.js defines a function called saveClick().

A button on the main form opens another window where the users enter some data, make selections, etc. Then they click on the OK button.

I transfer the data back to the underlying form (the main form). Now I want to execute main form's saveClick() method? I can't figure out the syntax or how to do this. Can anyone help?

Thank you.

khalidali63
04-14-2003, 11:05 AM
From parent window

windowRef = window.open("url"winName")
and then you can use this window reference object to call a method in the child window
windowRef.functionName();

from child window to invoke a function in parent window

top.opener.functionName();

Hope this helps

Cheers

Khalid

JSchwarz
04-14-2003, 11:23 AM
Got it working Khalid, thanks. Now maybe you could explain what I was doing wrong.

Originally, I had this in the child window's onLoad event:

openerForm = window.opener.document.forms[0];


And this in the OK button:

openerForm.saveClick();


When I changed the code to what you suggested in the OK button to this, it finally worked:

top.opener.saveClick();


Now, it seems to me that these lines do the same things. What's different?

Thanks for your help.
Jeff

khalidali63
04-14-2003, 11:40 AM
the variable you have defined points to the first form element in the document,where as top.opener.points to the parent window that has javascript function called saveClick().

Mucho difference

:-)

Khalid

JSchwarz
04-14-2003, 01:44 PM
Yes, that is a big difference. I get it now. Thanks again.
Jeff

JSchwarz
06-05-2003, 10:22 AM
OK, same type of question: How can I create a generic reference to the current form?

I have JavaScript.js referred to in a form's header via the following:
<SCRIPT LANGUAGE='JavaScript' SRC='/ASSIST/ASSIST.nsf/JavaScriptLib.js/'></SCRIPT>
In JavaScript.js is a function called initialize(), which has the following line:
thisForm = document.forms[0];
I call initialize() from the form's onLoad event. This has worked great for obtaining a general reference to the current form for ALL of the forms in my application... until now.

Now I have a page with two forms on it. The second form's onLoad event calls initialize(). However, thisForm is (obviously) pointing to the first form on the document. I can't figure out how to make a generic reference to the current form (I can't use the form name, because that's different on each form).

Does anyone know how to create a generic reference to the current form?

Thanks,
Jeff

medc77
12-15-2005, 12:34 AM
from child window to invoke a function in parent window

top.opener.functionName();

Khalid


this message is really old, but can anyone help me.

I have the same scenario above except that the function i want to call is within an iframe within the top.opener.

so the reference would be something like:

top.opener.THEIFRAMEREFERENCE.THEFUCNTIONTOEXECUTE

can anyone suggest the actual code... i've tried everything.

thanks.