next up previous contents
Next: Checkboxes Up: Forms: Facilitating User Input 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:

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:

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>

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