faqts : Computers : Programming : Languages : JavaScript : Forms : Radio buttons

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

104 of 117 people (89%) answered Yes
Recently 5 of 10 people (50%) answered Yes


How can I uncheck a radio button group?

Mar 20th, 2000 03:43
Martin Honnen,

Only one radio button in a group can be checked so you just have to 
loop through to find that button and change its checked property.
The following contains a function doing it plus two examples applying 
the function, the case of the group of consisting of just one button is 
function uncheckRadioGroup (radioButtonOrGroup) {
  if (radioButtonOrGroup.length) { // we have a group
    for (var b = 0; b < radioButtonOrGroup.length; b++)
      if (radioButtonOrGroup[b].checked) {
        radioButtonOrGroup[b].checked = false;
    radioButtonOrGroup.checked = false;
<FORM NAME="formName">
<INPUT TYPE="radio" NAME="aRadioGroup" VALUE="Kibo">
<INPUT TYPE="radio" NAME="aRadioGroup" VALUE="Xibo">
<INPUT TYPE="radio" NAME="aRadioGroup" VALUE="Maho">
<INPUT TYPE="button" VALUE="uncheck"
<INPUT TYPE="radio" NAME="aRadio" VALUE="Kibo">
<INPUT TYPE="button" VALUE="uncheck"