Forums

This topic is locked

Sending Variables Between Windows

Posted 18 Jul 2006 18:41:28
1
has voted
18 Jul 2006 18:41:28 Matt Bailey posted:
Does anyone know how to send a variable from a 'Popped Up' window back to a 'Parent' window using javascript? Basically I want to build a simple pop-up image browser so a user can pick an image and have the image's filename sent back to the main parent window for storage in a database.

___________________________________
"Some people say if you play a windows cd backwards it plays satanic messages. That's nothing, because if you play it forwards it installs windows!"

Replies

Replied 19 Jul 2006 16:42:57
19 Jul 2006 16:42:57 Matt Bailey replied:
Ok, after looking for a few days I finally found what I was looking for. Here's the code in case anyone else needs to know:

<b>Contents of first page (doc1.htm):</b>

<pre id=code><font face=courier size=2 id=code>&lt;script language="JavaScript"&gt;&lt;!--
function newWindow(file,window) {
msgWindow=open(file,window,'resizable=no,width=200,height=400');
if (msgWindow.opener == null) msgWindow.opener = self;
}
//--&gt;&lt;/script&gt;</font id=code></pre id=code>

<pre id=code><font face=courier size=2 id=code>&lt;form name="outputForm1"&gt;
&lt;input type="button" value="Open doc2.htm into window2" onClick="newWindow('doc2.htm','window2')"&gt;
&lt;br&gt;&lt;input name="outputField1" type="text" value=""&gt;
&lt;br&gt;&lt;input name="outputField2" type="text" value=""&gt;
&lt;/form&gt;</font id=code></pre id=code>

<b>Contents of second page/pop-up window (doc2.htm):</b>

<pre id=code><font face=courier size=2 id=code>&lt;script language="JavaScript"&gt;&lt;!--
function setForm() {
opener.document.outputForm1.outputField1.value = document.inputForm1.inputField1.value;
opener.document.outputForm1.outputField2.value = document.inputForm1.inputField2.value;
self.close();
return false;
}
//--&gt;&lt;/script&gt;</font id=code></pre id=code>

<pre id=code><font face=courier size=2 id=code>&lt;form name="inputForm1" onSubmit="return setForm();"&gt;
&lt;br&gt;&lt;input name="inputField1" type="text" value=""&gt;
&lt;br&gt;&lt;input name="inputField2" type="text" value=""&gt;
&lt;br&gt;&lt;input type="submit" value="Update opener"&gt;
&lt;/form&gt;</font id=code></pre id=code>

Bingo!

___________________________________
"Some people say if you play a windows cd backwards it plays satanic messages. That's nothing, because if you play it forwards it installs windows!"

Reply to this topic