Re: Dilemma with Radio Buttons

by Alan Carvalho <alancarv(at)sti.com.br>

 Date:  Mon, 20 Nov 2000 04:48:42 -0200
 To:  hwg-basics(at)mail.hwg.org
 In-Reply-To:  home
  todo: View Thread, Original
[Kate]
>It seems that the only way to deselect it is to select another.  But we
>don't want that.  We want to CLEAR ONLY this field (since it might be a
>mistake) without clearing the entire form.  Is there any way to either:
>a) program that in  OR
>b) instruct the user how to deselect it.

[Alan]

Yes, it's possible. Here is an example using a button to deselect all the
radio buttons in a group.

&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Clearing a radio button&lt;/title&gt;
  &lt;script language="javascript"&gt;
    function Zero(banana) {
      for (i=0; i&lt;banana.f_color.length; i++)
        banana.f_color[i].checked = false;
    }
  &lt;/script&gt;
&lt;body&gt;
  &lt;form name="test"&gt;
    What's your favorite color?
    &lt;input type="radio" name="f_color" value="1"&gt;Blue
    &lt;input type="radio" name="f_color" value="2"&gt;Red
    &lt;input type="radio" name="f_color" value="3"&gt;Green
    &lt;input type="radio" name="f_color" value="4"&gt;Yellow
    &lt;input type="button" value="Deselect"
    onclick="Zero(this.form);"&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Note: I used &lt; and &gt; instead the HTML brackets to avoid problems with
e-mail readers that understand HTML.

I hope help you.

Sorry the poor english.

Alan Carvalho
Sao Paulo, Brazil

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA