Spongebob Posted May 15, 2009 Share Posted May 15, 2009 I am just learning Javascript. The below code should show which radio button a user selects, but unfortunately it doesn't work. What am I doing wrong? Also, any recommendations for books on javascript and/or the use of javascript in conjunction with HTML? - Thanks in advance!<html><head></head><script language=javascript type="text/javascript">function select (radio) { if (Selection == "RadioGroup1_0") { document.write("You selected the top button"); } else { document.write("You selected the bottom button"); }}</script><body><p> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" /> Radio</label> <br /> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" /> Radio</label> <br /></p>onClick="select('radio')"></body> Link to comment Share on other sites More sharing options...
Ingolme Posted May 15, 2009 Share Posted May 15, 2009 Your code hardly makes sense.You have <script> tags outside the <head> and <body>, you're missing a closing <html> tag.The following portion of code makes no sense at all. onClick="select('radio')"> I don't see where the variable "Selection" is declared and where its value comes from. if (Selection == "RadioGroup1_0") { Link to comment Share on other sites More sharing options...
chibineku Posted May 15, 2009 Share Posted May 15, 2009 As Ingolme said, there are numerous errors in there.I think this is the sort of thing you mean (lifted almost exactly from the W3School examples): <html><head><script type="text/javascript">function check(browser) { alert("Your favourite browser is: "+browser); }</script></head><body><p>What's your favorite browser?</p><form><input type="radio" name="browser" onclick="check(this.value)" value="Internet Explorer">Internet Explorer<br /><input type="radio" name="browser" onclick="check(this.value)" value="Firefox">Firefox<br /><input type="radio" name="browser" onclick="check(this.value)" value="Netscape">Netscape<br /><input type="radio" name="browser" onclick="check(this.value)" value="Opera">Opera<br /></form></body></html> Link to comment Share on other sites More sharing options...
Spongebob Posted May 15, 2009 Author Share Posted May 15, 2009 Thank you both very much. Chibineku, thank you for the working example, I will study it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.