darknessmdk Posted July 2, 2008 Share Posted July 2, 2008 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> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 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> Quote Link to comment Share on other sites More sharing options...
darknessmdk Posted July 3, 2008 Author Share Posted July 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
darknessmdk Posted July 3, 2008 Author Share Posted July 3, 2008 I had wanted to do this with a loop, but if it can't be done I'll use this method, Thank you Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.