Jump to content

Newbie Questions


Spongebob
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...