Click to See Complete Forum and Search --> : radio buttons


yellowboy
05-17-2003, 09:54 PM
how do you tell which button is selected in a set of radio buttons
i want it so that it will add values of radio buttons on clicking an image but things like document.form1.b1.checked say that checked is not an object...what is the proper syntax for testing if a button is checked?

khalidali63
05-17-2003, 10:09 PM
the betterway of finding which radio button is selected is as follows.

1. define as many radio button
elements
2. all of the radio button should have the same name
name = "rd"
for all of them.

This will create an array of all the radio button elements,and you can go through and find out which one is checked

var len = document.formName.rd.length;

now go through the array to see whcih one is checked

for(var x=0;x<len;x++){
if(rd[x].checked){
//this button is checked d whatever you want to do here
}
}