Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Check Boxes

The simplest input type is a check box, which appears as a small square the user can select or deselect by clicking. You must give each check box a name. If you want a check box to be checked by default when the form comes up, include the checked attribute. For example, the following would make two check boxes:

<input type="checkbox" name="baby" checked /> Baby Grand Piano
<input type="checkbox" name="mini" /> Mini Piano Stool

The one labeled Baby Grand Piano would be checked. (The user would have to click it to turn it off if he didn't want a piano.) The one marked Mini Piano Stool would be unchecked to begin with, so the user would have to click it to turn it on.

When the form is submitted, selected check boxes appear in the form result:

baby=on

Blank (deselected) check boxes do not appear in the form output at all.

Share ThisShare This

Informit Network