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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass value from Pop-up to Hidden Form Field on Parent window

Status
Not open for further replies.

rudy23

Programmer
Feb 12, 2004
31
US
This topics been covered before but it wasnt resolved. So can this be done at all?

I need to pass a value from the child window and assign it to a hidden form field in the Parent window.

Here is the sample code. (not mine just took it from a previous post)

Main Window
Code:
<html>
<head>
<title>IRC Database Management</title>

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

</head>
<form name="place">

<input type=text name=theBox onclick="javascript:openMe();">
<input type=hidden name=window>

</form>
</html>
PopUp Window
Code:
<HTML>
<HEAD>
<TITLE>Deluxe Advertising Entry Form</TITLE>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<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="Click Me" onClick="setOther();">

</form>
</html>

Any help appreciated guys.
 
try this

window.opener.document.place.theBox.value = document.myForm.thisBox.value;
window.opener.document.place.window.value = document.myForm.window1.value;

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Nopes. I even tried passing a hard coded value. It can pass it to a text box but not to a Hidden Form Field.
 
sure it can I do it all the time. so probably something simple is a miss. What browser? what OS?

you might also add a default value to the hidden field

Code:
<form name="place">

<input type="text" name="theBox" onclick="javascript:openMe();">
<input type="hidden" name="window" [COLOR=red]value=""[/color]>

</form>

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
I know this is a workaround - but it has worked for me. Put a function on the parent page that accepts 2 variables as parameters and in that function populate your form. Then the child window only needs to call the parent's function passing the parameters. Like this:
Code:
--- in the parent add this
<script>
function populate(box1,hidden1) {
  var form=document.getElementById('place');
  form.theBox.value = box1;
  form.windows.value = hidden1;
}
</script>

--- in the child add this:
<script>
function sendToParent() {
  var form=document.getElementById('myForm');
  opener.populate(form.thisBox.value,form.window1.value);
}
</script>

--- and change the onclick in the popup to call sendToParent()

Does that make sense - again it is a work around, but it makes the naming convention much less problematic.

Einstein47
(&quot;The pure and simple truth is rarely pure and never simple.&quot; - Oscar Wilde)
 
Einstein47. Thats working. Doesnt hurt to add another function to the main page.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top