Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Radio Buttons

Radio buttons, where only one choice can be selected at a time, are almost as simple to implement as check boxes. Just use type="radio" and give each of the options its own input tag, but use the same name for all of the radio buttons in a group:

<input type="radio" name="card" value="v" checked /> Visa
<input type="radio" name="card" value="m" /> MasterCard

The value can be any name or code you choose. If you include the checked attribute, that button is selected by default. (No more than one radio button with the same name can be checked.)

If the user selects MasterCard from the preceding radio button set, the following is included in the form submission to the server script:

card=m

If the user doesn't change the default checked selection, card=v is sent instead.

Share ThisShare This

Informit Network