Entry
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
covered:
<HTML>
<HEAD>
<SCRIPT>
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;
break;
}
}
else
radioButtonOrGroup.checked = false;
}
</SCRIPT>
</HEAD>
<BODY>
<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"
ONCLICK="uncheckRadioGroup(this.form.aRadioGroup)"
>
<BR>
<INPUT TYPE="radio" NAME="aRadio" VALUE="Kibo">
<INPUT TYPE="button" VALUE="uncheck"
ONCLICK="uncheckRadioGroup(this.form.aRadio)"
>
</FORM>
</BODY>
</HTML>