I'm a javascript newb so this is probably pretty basic, but I'm having a problem with processing radio buttons. I have a series of radio buttons on the a form which I want to loop through and verify that none of the options are checked.
Let's say that I have radio buttons called btn1, btn2, and btn3 and each has two options. I then set a for loop (we'll say I'm using the variable 'c') to process through the buttons.
My first attemp was to try this:
mybtn=document.getElementById(btn+c)
but it seemed to get a handle on the first option in the button rather than the group, so I changed it to this:
btnGrp = document.getElementById(btn+c).parentElement
I then try to process through the options with this code:
for (var x=0;x<btnGrp.childNodes.length;x++){
btnGrp.childNodes[x].checked = false
}
The problem with this is that while there are two options for my radio button, there are 5 child nodes and not all of them have the 'checked' property, so my code chokes.
Long stroy short, what's the best way to process through a series of radio buttons and make sure that all options are unchecked?


Reply With Quote
Bookmarks