[thelist] Uncheck Items in Radio Button List

Ken Snyder ksnyder at coremr.com
Wed Jun 6 15:34:02 CDT 2007


Matt Warden wrote:
> Either way, I would suggest you rethink your use of radio buttons vs.
> some other element. Alternatively, offer a "none" option and select it
> by default.
>
>   
Casey,

To me, it sounded like you are trying to uncheck all items after the 
user has already checked an item.  Perhaps you can explain your problem 
in more detail...

I don't know anything about .NET or how it wraps JavaScript, but the 
JavaScript is like this.

<form name="myform">
<input type="radio" name="fruits[]" value="1" /> Apple
<input type="radio" name="fruits[]" value="2" /> Orange
...
</form>
<script language="javascript" type="text/javascript">
function uncheckAllRadios() {
  var radioGroup = document.forms['myform'].elements['fruits[]'];
  for (var i=0; i<radioGroup.length; i++) {
    radioGroup[i].checked = false;
  }
}
</script>

You'll notice that radios are accessed as a DOM NodeList object when 
using the elements in a form.  You can iterate through that collection 
and manipulate each radio.

--Ken



More information about the thelist mailing list