Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting selected radio button.

radio button groups

Detecting selected radio button.

by  GIGN  Posted    (Edited  )
When radio buttons are created, we give them all the same name. These now are a group, and must be accessed using array notation. To detect which one has been selected we need to loop through them all, asking each one whether or not it has been chosen:
[color blue]
function getValue(Obj_checkBoxGroup){


for(j=0; j< Obj_checkBoxGroup.length; j++){

if(Obj_checkBoxGroup[j].checked){
return checkBoxGroup [j].value;
}

else{}
}

}

[/color]
Send the function the group to work with like:[color red]
<form>
...
<input type="button" onClick="getValue(names)">
<input type="checkbox" name="names" value="Gus">
<input type="checkbox" name="names" value="Tony">
...
</form>
[/color]

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top