next up previous
Next: Checkboxes Up: Entering Data Previous: Associating labels with text

Radio Buttons

This INPUT type is best used when you want the user to select one of a limited number of choices. For example, suppose you wanted to find out which computer operating system your users prefer. Of the six options provided, the user should only be able to pick one. The list will look something like this:

Your favorite computer operating system:
Macintosh
DOS
Windows
Windows95
OS/2
UNIX

What happens, as you have seen, is that only one option can be chosen. If an option is already selected, then choosing another option will de-select the previously chosen option and select the new option. Since there is nowhere for the user to enter a value, however, the value of each option must be specified in the HTML markup itself, using the VALUE attribute.

To produce a radio button simply specify the radio value to the type attribute. For Example:

<P>
Your favorite computer operating system:<BR>
<INPUT type="radio" name="fav_os" value="mac">Macintosh<BR>
<INPUT type="radio" name="fav_os" value="dos">DOS<BR>
<INPUT type="radio" name="fav_os" value="win">Windows<BR>
<INPUT type="radio" name="fav_os" value="win95">Windows95<BR>
<INPUT type="radio" name="fav_os" value="os2">OS/2<BR>
<INPUT type="radio" name="fav_os" value="unix">UNIX<BR>
</P>

Again, the use of the Name/Value attribute pair is required for (multiple) radio-button input to CGI scripts.



Dave Marshall
9/28/2001