Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass values child to parent

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
GB
I have an edit page with a variety of values sourced from a recordset. I have a child window where the user can change two of those field values, how can I pass these back to the parent window and perhaps close the child window at the same time?

TIA

Struth "It's life Jim, but not as we know it!"
 
Just to make sure we understand: the edit page is in the parent window and in it the document has javascript with a window.open statement. The window opened is the child window.

You can't actually put anything new in the document in the parent window. What you can do is rebuild the document with new data. Ah but you know that.

In the child window is a form to collect a couple of new values. Call the script that builds the document in the child window, corrector.asp.

Here is how I do that.

the form in the child window submits to itself.
<form action=&quot;corrector.asp&quot;>
and a submit button like this.
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Correct It&quot;>

At the beginning of corrector.asp check to see whether it was called from itself or from the parent window document.

if(Request.Form(&quot;submit&quot;) == &quot;Correct It&quot;){
//The rest of the story.
} else {
//Build the update form.
}

Here is the rest of the story.

First, UPDATE the database with the values from the edit form. Then, and this is the cool part, build a document that will never be seen like so -
Code:
<HTML>
<SCRIPT>
window.opener.location=&quot;my_main_document.asp&quot;;
window.self.close();
</SCRIPT>
</HTML>

That will call the script to rebuild the document in the parent window. Since at this point the database has the new values, the rebuilt document will get the new values.

Then it closes the child window.

 
Beautifully simple, works beautifully.

Many thanks

Struth

very clever Mr Bond! &quot;It's life Jim, but not as we know it!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top