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!

passing values from a pop-up

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello -

Is it possible to pass values from an input form in a pop-up window back to a form in the parent window with javascript? - I've been playing around all day - but if someone could point me to some sample code, I'd be greatly appreciative. Basically the below outlines it -

<form action=&quot;cgi.cgi&quot;>

<tr><td align=center WIDTH=&quot;200&quot; BGCOLOR=&quot;#F8F1F1&quot;>Individual Vendor ID Number (add '1' to previous)</a></td>
<td><input type=text name=&quot;vendor_number&quot; size=25></td></tr>


<script language=&quot;JavaScript&quot;>

function surfto(form) {
var myindex=form.select1.selectedIndex
if (form.select1.options[myindex].value != &quot;0&quot;) {
location=form.select1.options[myindex].value;}
}
//-->
</SCRIPT>

<script language=javascript
type=&quot;text/javascript&quot;>

function newWindow(open) {

mailWindow = window.open(open,'mailWin','width=300,height=300,toolbar=no,resize=yes,scrollbars=yes location=yes')

mailWindow.focus()

}

</script>

<SELECT NAME=&quot;select1&quot; onChange=&quot;surfto(this.form)&quot; SIZE=1>
<OPTION SELECTED VALUE=&quot;0&quot;>Does the vendor offer any special items?
<option value=&quot;javascript:newWindow(' <option value=&quot;&quot;>No
</SELECT>

<tr><td align=center WIDTH=&quot;200&quot; BGCOLOR=&quot;#F8F1F1&quot;>Phone Number</a></td>
<td><input type=text name=&quot;phone&quot; size=25></td></tr>

<tr><td align=center WIDTH=&quot;200&quot; BGCOLOR=&quot;#F8F1F1&quot;>Contact Email Address</a></td>
<td><input type=text name=&quot;email&quot; size=25></td></tr>

<input type=&quot;submit&quot; value=&quot;Enter item in database&quot;>

From the drop down, a window pops-up if the person selects &quot;yes&quot; - for the person to fill out an additional form of input options, if and only if they pick 'yes' from the drop-down menu.

So - my question is, once they fill out the form on the pop-up window, can someone tell me how to get those input entries back into the original form so they will be processed with other entry items?

Thanks so much!

Nathan
 
Well, you can use window.opener.formName etc... to access your form, then you can go from there. Or, you can disable the extra stuff with document.formName.elementName.disabled = true; and then to enable them: document.formName.elementName.disabled = false;

hope that helps... -Greg :-Q
 
You can grab them from a pop-up by just setting the appropriate form values - you can even call a function which resides in the original window.
The original window which spawns the pop-up is called the opener, not the parent. So from the pop-up you can actually just call something like:

opener.formName.formElement.value = formelem.value;


opener.document.formName, and opener.formName are equivalent.

By wrapping all that red stuff in a function in the opener - it saves you writing it to the new page -just a bit of convenience. e.g.

function insertThis(location,value){
document.F1.elements[location].value = value;
}


and this is called from your pop-up using opener.insertThis() - location is the name of the form element who's value you want to set(passed in quotes), and value is the value from the pop-up's form.
b2 - benbiddington@surf4nix.com
 
not to contradict what bangers has said -- but here is a very simplified working version of this in a FAQ:

faq216-692

:)
Paul Prewett
 
Guys,

Thanks - that was really helpful. I've gotten the javascript to work for text values; however, I'm needing to pass the values back to the opener window as hidden, so I've go the same syntax as in the FAQ that link9 pointed me to; however, what extra code would I add to make this work for hidden values? For example, this works for the following -

(the opener Window)

<html>
<head>
<title>IRC Database Management</title>

<script language=&quot;javascript&quot;>
function openMe(){
var x = window.open('add_item.htm', 'newWindow');
}
</script>

</head>
<form name=&quot;place&quot;

<input type=text name=theBox>
<input type=hidden name=window>

</form>
</html

(the pop-up window)

<HTML>
<HEAD>
<TITLE>Deluxe Advertising Entry Form</TITLE>

<BODY BGCOLOR=&quot;#FFFFFF&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000FF&quot; VLINK=&quot;#800080&quot;>

<script language=javascript>
function setOther(){
window.opener.place.theBox.value = document.myForm.thisBox.value;
window.opener.place.window.value = document.myForm.window1.value;
}
</script>
</head>
<body>
<form name=myForm>
<input type=text name=thisBox>
<input type=text name=window1>
<input type=button value=&quot;Click Me&quot; onClick=&quot;setOther();&quot;>

</form>
</html>



When I do this, the &quot;thisBox&quot; field is passed to the &quot;theBox&quot; field in the opener, but I can get the &quot;window1&quot; field in the pop-up to pass to the hidden &quot;window&quot; field in the opener.

I really appreciate any help - and thanks in advance and for everything so far!

Nathan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top