Learn HTML Code Tutorial Reference Guide

TYPE = RADIO

RADIO is used to create a series of choices of which only one can be selected. The term "radio button" comes from the buttons for the radio in an automobile, where selecting one radio station automatically de-selects all the others. HTML radio buttons are created by using several <INPUT TYPE=RADIO> buttons, all with the same name, but with different values. For example, this series of buttons allows you to choose one size for a pizza:

this code produces this
<FORM ACTION="../cgi-bin/mycgi.pl">
What size pizza?<P>

<INPUT TYPE=RADIO NAME="pizzasize" VALUE="S">small<BR>
<INPUT TYPE=RADIO NAME="pizzasize" VALUE="M">medium<BR>
<INPUT TYPE=RADIO NAME="pizzasize" VALUE="L">large<P>

<INPUT TYPE=SUBMIT VALUE="submit">
</FORM>
What size pizza?

small
medium
large

Note that it is the content of the VALUE attribute that is sent to the CGI, not whatever text happens to appear next to the radio button.

If one of the items should be the default selection, use the CHECKED attribute:

this code produces this
<FORM ACTION="../cgi-bin/mycgi.pl">
What size pizza?<P>

<INPUT TYPE=RADIO NAME="pizzasize" VALUE="S"         >small<BR>
<INPUT TYPE=RADIO NAME="pizzasize" VALUE="M" CHECKED >medium<BR>
<INPUT TYPE=RADIO NAME="pizzasize" VALUE="L"         >large<P>

<INPUT TYPE=SUBMIT VALUE="submit">
</FORM>
What size pizza?

small
medium
large

If no CHECKED attribute is used, different browsers have different ways of displaying the initial state of a series of radio buttons. Netscape and MSIE have none of the buttons selected. Mosaic selects the first button.




 

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   Privacy Policy   |   About
Copyright ©1997-2002 Idocs and ©2002-2014 HTML Code Tutorial