By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,886 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,886 IT Pros & Developers. It's quick & easy.

Radio button value

Claus Mygind
100+
P: 571
In my script I used to test the value of the radio button to verify which button was selected. I was able to do that because all the buttons have the same name. If I want to use the the proper
Expand|Select|Wrap|Line Numbers
  1. document.getElementById()
notation.

Will I have to:
1) assign a unique id to each button
2) test if that id is "checked"

Or is it proper to use
Expand|Select|Wrap|Line Numbers
  1. document.getElementByName()
and then test the value in the same manner I did before?
May 29 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Yes, the IDs need to be unique, and yes, document.getElementsByName() is OK (don't forget the "s") and probably easier to deal with.
May 29 '08 #2

Claus Mygind
100+
P: 571
I really cannot get any of it to work.
I use FireFox and any reference to
Expand|Select|Wrap|Line Numbers
  1. document.getElementByName()
  2. document.getElementByNames()
  3. document.getElementByTagName()
generates an error "is not a function".

Now I am trying with Id and giving a unique id to each button, hopefully that will work.
May 29 '08 #3

acoder
Expert Mod 15k+
P: 16,027
There's no getElementByName() method, it's getElementsByName() - notice the difference (see link).
May 29 '08 #4

Claus Mygind
100+
P: 571
Thanks. That had been bothering me for awhile.
May 29 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You're welcome.
May 29 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.