I have four radio buttons, all with the same Name value, but different Value values.
<input type="radio" name="cars" value="vw" />
<input type="radio" name="cars" value="dodge" />
Etc.
If there someway I can extract the value of the selected node from that list?
document.getElementsByName("cars").value type of thing?
I ended up just doing a loop, and looking for whichever node had .checked as true - but I'm hoping their is a non-loop way to do this.
-
-
Nope, the loop is the correct way to do it. You should also probably check !elems[i].disabled if you're writing a general-purpose function.
-
The problem is you are using name attribute but you should use distinct id attributes to reference them via getElementById().
Example:
<input type="radio" id=''cars0" name="cars[0]" value="vw" />
<input type="radio" id="cars0" name="cars[1]" value="dodge" />
just my 2 cents -
Its against DOM to reference more than one element under the same ID. Not sure how you can expect browsers to consistently handle this, some may return an array of elements and other would just .. not.
-
stevo_ wrote:Its against DOM to reference more than one element under the same ID. Not sure how you can expect browsers to consistently handle this, some may return an array of elements and other would just .. not.
I'm not using ID's...I'm using the name attribute - just as DOM standards suggest, if I'm not mistaken.
-
jsampsonPC wrote:

stevo_ wrote: Its against DOM to reference more than one element under the same ID. Not sure how you can expect browsers to consistently handle this, some may return an array of elements and other would just .. not.
I'm not using ID's...I'm using the name attribute - just as DOM standards suggest, if I'm not mistaken.
he was replying to zproxy.....
the loop is the correct way AFAIK -
Ang3lFir3 wrote:

jsampsonPC wrote: 
stevo_ wrote: Its against DOM to reference more than one element under the same ID. Not sure how you can expect browsers to consistently handle this, some may return an array of elements and other would just .. not.
I'm not using ID's...I'm using the name attribute - just as DOM standards suggest, if I'm not mistaken.
he was replying to zproxy.....
the loop is the correct way AFAIK
Yes I was, sorry I have the admit the interface is a little confusing because- 'reply' is right next to the user information and is then obviously repeated for each post, I didn't notice and just presumed Reply would mean 'reply to this post'.
Live n learn..
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.