unistake Posted July 11, 2009 Share Posted July 11, 2009 ok, im starting this again. Hi all! I am trying to link up 3 radio buttons and JS so that when selected, JS executes the correct if statements. The code I have attempted to make so far is below, however I can not seem to get any of the JS below to work. Could someone show me where I am going wrong? Also preferably instead of using the form button to execute the JS, I would like it if when the correct radio button is clicked, that the JS would run from that command Thanks, Tim <head> <script type="text/javascript"> function calc () { var radiochoice; for(i=0;i<document.calcform.typeofbet.length;i++) { if(document.calcform.typeofbet[i].checked) radiochoice = document.calcform.typeofbet[i].value; } if (radiochoice=="qualifier") { function qualifier () } if (radiochoice=="sr") { function sr () } if (radiochoice=="snr") { function snr () } function qualifier () { document.write("this is function qualifier!"); } function sr() { document.write("this is function SR!"); } function snr() { document.write("this is function SNR!"); } } </script> </head> <body> <form name="calcform"> <p> <input type="radio" name="typeofbet" value="qualifier" checked> radio1 <input type="radio" name="typeofbet" value="freesr"> radio2 <input type="radio" name="typeofbet" value="freesnr"> radio3<br> <input type="submit" value="Click To Calculate" onClick="calc();"> </p> </form> /////////// I want to show the text from each function here............ //////////////////////////////// </body> Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/ Share on other sites More sharing options...
BillyBoB Posted July 11, 2009 Share Posted July 11, 2009 It seems that you are trying to set the functions twice; once when you try to call to them and once when you actually set them. try changing: if (radiochoice=="qualifier") { function qualifier () } if (radiochoice=="sr") { function sr () } if (radiochoice=="snr") { function snr () } to: if (radiochoice=="qualifier") { qualifier(); } if (radiochoice=="freesr") { sr(); } if (radiochoice=="freesnr") { snr(); } edit: i was looking at the if statements and the values don't match up either. Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/#findComment-873454 Share on other sites More sharing options...
unistake Posted July 11, 2009 Author Share Posted July 11, 2009 Thanks BillyBob, but it still does not seem to work. Also should the function calc() have a close bracket } just before the function qualifier? The code I have is now... <head> <script type="text/javascript"> function calc () { var radiochoice; for(i=0;i<document.calcform.typeofbet.length;i++) { if(document.calcform.typeofbet[i].checked) radiochoice = document.calcform.typeofbet[i].value; } if (radiochoice=="qualifier") { qualifier(); } if (radiochoice=="freesr") { sr(); } if (radiochoice=="freesnr") { snr(); } function qualifier () { document.write("this is function qualifier!"); } function sr() { document.write("this is function SR!"); } function snr() { document.write("this is function SNR!"); } } </script> </head> <body> <form name="calcform"> <p> <input type="radio" name="typeofbet" value="qualifier" checked> radio1 <input type="radio" name="typeofbet" value="freesr"> radio2 <input type="radio" name="typeofbet" value="freesnr"> radio3<br> <input type="submit" value="Click To Calculate" onClick="calc();"> </p> </form> </body> What values dont match Billybob? Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/#findComment-873461 Share on other sites More sharing options...
BillyBoB Posted July 11, 2009 Share Posted July 11, 2009 You changed them now but the values of the if statements. but yes the calc function will need to be closed before the other functions Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/#findComment-873466 Share on other sites More sharing options...
unistake Posted July 11, 2009 Author Share Posted July 11, 2009 Ok thanks, the script is still not displaying the document.write within the if statements. Do you know how I can get that working? Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/#findComment-873485 Share on other sites More sharing options...
BillyBoB Posted July 11, 2009 Share Posted July 11, 2009 Do you have it hosted somewhere? So i can test it? Link to comment https://forums.phpfreaks.com/topic/165594-linking-radio-buttons-and-if-statements/#findComment-873490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.