unistake Posted August 6, 2009 Share Posted August 6, 2009 Hi all, got a simple problem for you I am trying to create an outcome by clicking on radio buttons, I cant seem to get the 'document.write' to work and display the text at the bottom of the radio buttons, with those radio buttons still showing. The code I have is: <html> <head> <script type="text/javascript"> function calc (){ selection = document.getElementsByName("typeofbet"); for(i=0; i<selection.length; i++){ if(selection[i].checked == true){ var selected = selection[i].value; } } if(selected == "qualifier"){ qualifier(); }else{ if(selected == "freesr"){ sr(); }else{ if(selected == "freesnr"){ snr(); } } } } function qualifier (){ document.write('this is the qualifier!'); } function sr(){ document.write('this is the sr!'); } function snr(){ document.write('this is the snr!'); } </script> </head> <body> <form name="calcform"> <p> <input type="radio" name="typeofbet" value="qualifier" onClick="return calc();"> qual <input type="radio" name="typeofbet" value="freesr" onClick="return calc();"> sn <input type="radio" name="typeofbet" value="freesnr" onClick="return calc();"> snr </p> </form> </body> </html> Thanks for the heads up Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 dont use document.write. it sucks. Instead make make a span or div tag, and use javascript to effect the innerHTML of the elemt. Something like <html> <head> <script type="text/javascript"> function calc (){ text = document.getElementById("text"); selection = document.getElementsByName("typeofbet"); for(i=0; i<selection.length; i++){ if(selection[i].checked == true){ var selected = selection[i].value; } } if(selected == "qualifier"){ qualifier(); }else{ if(selected == "freesr"){ sr(); }else{ if(selected == "freesnr"){ snr(); } } } } function qualifier (){ //document.write('this is the qualifier!'); text.innerHTML = 'this is the qualifier!' } function sr(){ // document.write('this is the sr!'); text.innerHTML = 'this is the sr!' } function snr(){ // document.write('this is the snr!'); text.innerHTML = 'this is the snr!' } </script> </head> <body> <form name="calcform"> <p> <input type="radio" name="typeofbet" value="qualifier" onClick="return calc();"> qual <input type="radio" name="typeofbet" value="freesr" onClick="return calc();"> sn <input type="radio" name="typeofbet" value="freesnr" onClick="return calc();"> snr </p> <span id="text"></span> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
unistake Posted August 6, 2009 Author Share Posted August 6, 2009 fantastic! thanks for the help! 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.