JavaScript Forum JS Made Easy: Free JavaScripts Tutorials Example Code
About This Product
FontsMadeEasy.com
 
The Business Internet
Find it on This page:
 
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet

     
Jsmadeeasy Forums Home   Search   Login   Register   Member List  
JS Made Easy  > JavaScript programming  > Re:  
 
Display using:  
Previous Thread :: Next Thread 
 Author Thread: Carrying variable between windows
scott is not online. Last active: 7/28/2004 3:52:08 PM scott
Joined: 28 Jul 2004
Total Posts: 2
 
Carrying variable between windows
Posted: 22 May 2002 02:36 AM
I have a form for user input. Next to one of the input boxes I give the user the option to open a new window to select a value. The new window pops up and a value is selected which causes another window to open and the original pop up to close. I the need the new window to be able to write the value into the form.

Assume the form name is form1 and the input box is input1, I have tried the following and non work:
window.form1.input1.value = x;
window.document.form1.input1.value = x;
parent.window.form1.input1.value = x;
opener.document.form1.input1.value = x;

etc, etc...
Any ideas?


qsaaiman is not online. Last active: 5/30/2006 4:23:08 AM qsaaiman
Top 25 Poster
Joined: 28 Jul 2004
Total Posts: 21
 
Re:
Posted: 22 May 2002 04:12 AM
Hey.

*********************************start form.asp
file 1: (The page with the form) (call it form.asp for testing)

<script language="JavaScript">
function get_value() {
window.open ("formpop.asp", "window1","width=250,height=250,status=no,resizable=no,top=200,left=200");
}
</script>
<form name="form1">
<input type="Text" name="input1">
<input type="Button" value="Pick" onclick="get_value()">
</form>

*********************************end form.asp

*********************************Start formpop.asp
file 2: (The popup window. called formpop.asp for testing.)

<script language="JavaScript">
function send_val(val) {
self.opener.form1.input1.value = val;
window.close()
}
</script>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr><td onclick="send_val(1)" style="cursor:hand">Value 1</td></tr>
<tr><td onclick="send_val(2)" style="cursor:hand">Value 2</td></tr>
<tr><td onclick="send_val(3)" style="cursor:hand">Value 3</td></tr>
</table>

*********************************end formpop.asp

Just create the 2 files & test them to see if they do what you want.
insert the code in the <body> tag.

HTH.

Regards

Quintin Saaiman
Department of Labour
IT Systems

Quintin Saaiman
scott is not online. Last active: 7/28/2004 3:52:08 PM scott
Joined: 28 Jul 2004
Total Posts: 2
 
Re:
Posted: 22 May 2002 04:43 AM
One level more complicated. WindowA opens windowB. WindowB then opens WindowC which closes WindowB. WindowC now needs to assign a value to WindowA, FormA, InputA.

ie: opener can't be found because windowB is closed.

qsaaiman is not online. Last active: 5/30/2006 4:23:08 AM qsaaiman
Top 25 Poster
Joined: 28 Jul 2004
Total Posts: 21
 
Re:
Posted: 22 May 2002 05:02 AM
Ok this is the only way I could get it to work:

******* form.asp *******
<script language="JavaScript">
function get_value1() {
window.open("formpop.asp", "window1","width=250,height=250,status=no,resizable=no,top=200,left=200");
}
function get_value2() {
window.open("formpop2.asp", "window2","width=250,height=250,status=no,resizable=no,top=200,left=200");
}
</script>
<form name="form1">
<input type="Text" name="input1">
<input type="Button" value="Pick" onclick="get_value1()">
</form>
************************

***** formpop1.asp *****
<script language="JavaScript">
function send_val(val) {
opener.form1.input1.value = val;
window.close()
}
function get_it() {
opener.get_value2()
window.close()
}
</script>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr><td onclick="send_val(1)" style="cursor:hand">Value 1</td></tr>
<tr><td onclick="send_val(2)" style="cursor:hand">Value 2</td></tr>
<tr><td><input type="Button" value="Pick" onclick="get_it()"></td></tr>
</table>
************************

***** formpop2.asp *****
<script language="JavaScript">
function send_val(val) {
opener.form1.input1.value = val;
window.close()
}
</script>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr><td onclick="send_val(1)" style="cursor:hand">Value 1</td></tr>
<tr><td onclick="send_val(2)" style="cursor:hand">Value 2</td></tr>
</table>
************************

Quintin Saaiman
Department of Labour
IT Systems

Quintin Saaiman
Previous Thread :: Next Thread 
Goto to page:  Prev Next
 
Jsmadeeasy.com  > JS Made Easy  > JavaScript programming  > Re: