W3C home > Mailing lists > Public > www-html@w3.org > June 2003

RE: Deselect a radio button group

From: Peter Foti (PeterF) <PeterF@SystolicNetworks.com>
Date: Thu, 12 Jun 2003 15:53:18 -0400
Message-ID: <A10A983C9DFBD4119F0300104B2EA6B72602F0@ZIPPY>
To: "'Price, Chad'" <cprice@fcg.com>, "'www-html@w3.org'" <www-html@w3.org>
This may be off topic, but here's a reply anyhow.


radio buttons 
Radio buttons are like checkboxes except that when several share the same
control name, they are mutually exclusive: when one is switched "on", all
others with the same name are switched "off". The INPUT element is used to
create a radio button control. 
If no radio button in a set sharing the same control name is initially "on",
user agent behavior for choosing which control is initially "on" is
undefined. Note. Since existing implementations handle this case
differently, the current specification differs from RFC 1866 ([RFC1866]
section, which states: 
At all times, exactly one of the radio buttons in a set is checked. If none
of the <INPUT> elements of a set of radio buttons specifies `CHECKED', then
the user agent must check the first radio button of the set initially.
Since user agent behavior differs, authors should ensure that in each set of
radio buttons that one is initially "on".

Note the last line.  The spec recommends that one should always be checked,
though does not require it.

Having said that, you could use JavaScript to turn them all off. 

<form name="form1" action="">
   <input type="radio" name="myradio" value="foo"> foo<br>
   <input type="radio" name="myradio" value="bar"> bar<br>
   <input type="button" value="clear radios"

<script type="text/javascript">
function clearRadios( radioname )
   for( i = 0; i < document.form1[radioname].length; i++ )
      document.form1[radioname][i].checked = false;

You could expand that even more to pass in the form name or form object if
you wanted a more generic solution that could be reused by other forms.

Peter Foti

>-----Original Message-----
>From: www-html-request@w3.org [mailto:www-html-request@w3.org]On Behalf
>Of Price, Chad
>Sent: Thursday, June 12, 2003 2:57 PM
>To: www-html@w3.org
>Subject: Deselect a radio button group
>The specification for radio buttons allows for a group of them 
>to be intitially without a selection.   Is there a way to make 
>a radio group such that no options are selected once on has 
>been chosen (for arguments sake, without supplying a 
>reset/clear button or refreshing a page)?  I have a feeling 
>this cannot be done in IE (or maybe any other browser for that matter).

Received on Thursday, 12 June 2003 15:40:17 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:04 UTC