M.O.S. Studios Posted January 19, 2009 Share Posted January 19, 2009 Hey guys, i have this script that takes the information from this form and places it into another form (this script is ran withi a popup) <html> <head> <script type="text/javascript"> function sendToPageOne() { var thisValue = document.getElementById('image1').value; window.opener.form1.image1.value = thisValue; } </script> </head> <body> <table width="100%" height="100%" cellpadding="0" cellspacing="0" frame="0" border="0"> <form method="POST" action="account.php?actions=addpic" enctype="multipart/form-data"> <tr width='100%'><td width='100%' height='5'><a href='account.php?actions=addpic'><font size='2'><i>root</i></font></a></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#a4b9f7'><input type='submit' name='directory' value='upload/..' id='submitb'></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#779ff7'><input type='submit' name='directory' value='../../upload/cards' id='submitb'></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#779ff7'><input type='submit' name='directory' value='../../upload/test' id='submitb'></td></tr> </form> <form name="form2" action="browse.php" method="POST"> <tr width='100%'><td width='100%'> <input type="radio" name="image1" id=image1 value="" checked>None<br> <input type="radio" name="image1" id=image1 value="../../upload/1.jpg">1.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/2.jpg">2.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/2472178932_060c51e5a7[1].jpg">2472178932_060c51e5a7[1].jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/Crater.jpg">Crater.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/clistheader[1].jpg">clistheader[1].jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/cube.jpg">cube.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/gcube.jpg">gcube.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/test.jpg">test.jpg<br> <input type="submit" onclick="sendToPageOne();self.close();"; value="Send to page 1"> </td> </tr> </form> </table> </body> </html> at first it wasn't radio buttons it was a select box, it worked fine now i switched it to a radio buttons and its not working, i think that's because i should use GetElementname for a radio button. how ever when i switch it to that i still have no luck any ideas???? thanks in advance Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 19, 2009 Share Posted January 19, 2009 The problem has nothing to do with getElementById. The problem is that you are dealing with a radio group. With a select list you can find the value of the select list object. But, with a radio group each option has a value and there is no direct way to reference the selected value. To add to the problem, a radio group is treated differently if it has multiple options or only one option. I have a small custom function that will return that selected value of a radio group regardless of the number of options: function radioGroupValue(groupObj) { //Check if radio group has multiple options (i.e. is an array) if (groupObj.length) { //Iterrate through each option for (var i=0; i<groupObj.length; i++) { //Check if option is checked if (groupObj[i].checked) { //Return value of the checked radio button return groupObj[i].value; } } } //There is only one option in the radio group else if (groupObj.checked==true) { return groupObj.value; } //No option was selected return false; } Quote Link to comment Share on other sites More sharing options...
M.O.S. Studios Posted January 19, 2009 Author Share Posted January 19, 2009 Wow thats realy messed up i know very little java, i most use php, but what i need to do can only be done in java, to keep things moving im just going to keep it as a select list thanks for the code Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 19, 2009 Share Posted January 19, 2009 1. JavaScript (which is what we are talking about) is not Java. Two different things. 2. No need to go back to a select list. Just need to incorporate the function I posted. Try this: <html> <head> <script type="text/javascript"> function radioGroupValue(groupObj) { //Check if radio group has multiple options (i.e. is an array) if (groupObj.length) { //Iterrate through each option for (var i=0; i<groupObj.length; i++) { //Check if option is checked if (groupObj[i].checked) { //Return value of the checked radio button return groupObj[i].value; } } } //There is only one option in the radio group else if (groupObj.checked==true) { return groupObj.value; } //No option was selected return false; } function sendToPageOne() { var thisValue = radioGroupValue(document.form2.image1); window.opener.form1.image1.value = thisValue; } </script> </head> <body> <table width="100%" height="100%" cellpadding="0" cellspacing="0" frame="0" border="0"> <form method="POST" action="account.php?actions=addpic" enctype="multipart/form-data"> <tr width='100%'><td width='100%' height='5'><a href='account.php?actions=addpic'><font size='2'><i>root</i></font></a></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#a4b9f7'><input type='submit' name='directory' value='upload/..' id='submitb'></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#779ff7'><input type='submit' name='directory' value='../../upload/cards' id='submitb'></td></tr> <tr width='100%'><td width='100%' height='5' bgcolor='#779ff7'><input type='submit' name='directory' value='../../upload/test' id='submitb'></td></tr> </form> <form name="form2" action="browse.php" method="POST"> <tr width='100%'><td width='100%'> <input type="radio" name="image1" id=image1 value="" checked>None<br> <input type="radio" name="image1" id=image1 value="../../upload/1.jpg">1.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/2.jpg">2.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/2472178932_060c51e5a7[1].jpg">2472178932_060c51e5a7[1].jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/Crater.jpg">Crater.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/clistheader[1].jpg">clistheader[1].jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/cube.jpg">cube.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/gcube.jpg">gcube.jpg<br> <input type="radio" name="image1" id=image1 value="../../upload/test.jpg">test.jpg<br> <input type="submit" onclick="sendToPageOne();self.close();"; value="Send to page 1"> </td> </tr> </form> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
M.O.S. Studios Posted January 20, 2009 Author Share Posted January 20, 2009 I did it, it works 100%, should have just done it right away, lol thanks a million 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.