Jump to content

[SOLVED] Passing data from child window to parent window


darknessmdk

Recommended Posts

Hi all,

 

Heres my problem,  I am opening a popup window from the parent page, the popup contains a few radio buttons.

I am having problems passing the value of the selected radio button to a field on the parent page.  I recieve "undefined" in the text field on the parent page.

 

The script I am using works perfectly if all the fields in the popup window are named differently, however with the array of radio buttons they can't be named differently.

 

Heres the code for the parent window

<html>
<head>
<title>Master Form Page</title>
<script language="JavaScript" type="text/javascript">

var Fwin = null;
Fwin_Wid = 300;
Fwin_Hgt = 220;
Fwin_Left = (screen) ? screen.width/2 - Fwin_Wid/2 : 100;
Fwin_Top =  (screen) ? screen.availHeight/2 - Fwin_Hgt/2 : 100;
function openFormWin(url) {
Fwin = open(url,'Fwin','width='+Fwin_Wid+',height='+Fwin_Hgt+',left='+
Fwin_Left+',top='+Fwin_Top+',status=0');
setTimeout('Fwin.focus()',100);
}

</script>
</head>
<body>
<br>
<a href="#" onClick="openFormWin('buttest.html');return false;">Show Form</a>
<br>
<form name="mainForm"> 
Name
<input name="buttontemp" type="text"><br>

</form>
</body>
</html>

 

Here is the code for the popup window

 

<html>
<head>
<title>Pop Up Form</title>
<script language="JavaScript" type="text/javascript">

function setMaster() {
var mainForm = opener.document.mainForm;
var popForm = document.popForm;
var currEl;
for (var i=0; i<popForm.length; i++) {
currEl = popForm[i];
if (mainForm[currEl.name]) {
mainForm[currEl.name].value = popForm[currEl.name].value;
}
}
if (opener && !opener.closed) opener.focus();
self.close();
}

</script>
</head>
<body bgcolor="#426498">
<div align="right"><br>
<form name="popForm" onSubmit="setMaster()">
name:
<input type="radio" name="buttontemp" id="radio" value="Test Value">

<br>
<input type="radio" name="buttontemp" id="radio" value="Test Value22">
<br>

<input type="submit" value="DONE">
</form>
</div>
</body>
</html>

 

 

Link to comment
Share on other sites

Do you mean like this?

 

In the popup file:

<html>
<head>
<title>Pop Up Form</title>
<script language="JavaScript" type="text/javascript">
function setMaster()
{
var inputs = popForm.getElementsByTagName('input');
if (inputs[0].checked)
	opener.document.mainForm.buttontemp.value = "Value for 1st radio button";
else if (inputs[1].checked)
	opener.document.mainForm.buttontemp.value = "Value for 2nd radio button";
else
	opener.document.mainForm.buttontemp.value = "Value for neither radio button";
self.close();
}
</script>
</head>
<body bgcolor="#426498">
<div align="right"><br>
<form name="popForm" onSubmit="setMaster()">
name: 	<input type="radio" name="radio"><br>
<input type="radio" name="radio"><br>
<input type="submit" value="DONE">
</form>

</div>
</body>
</html>

Link to comment
Share on other sites

Well there will be more than two radio buttons, I'm just using two for testing right now. There will be 14 radio buttons total and the user has to pick one.

 

The problem is I can't seem to capture the value for the radio buttons.  I am assuming this is because they all have the same name in the form. I have no problem capturing values for text fields.

 

 

Link to comment
Share on other sites

You can use a loop. I think you would want to set up an array that contains the values that would correspond to the radio buttons in the order that they are written in the HTML. You would just loop through the inputs array (from getElementsByTagName()), stop when you found one that had a checked value that was true and then use the index of that radio in the inputs array to get the value from your array with the values.

 

Does that make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.