Jump to content

Newbie Questions


Spongebob

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...