ptg16476052
Creating Form Controls with the <input> Tag 335
12
Output ▼
To display the check box as checked, include the checked attribute , as follows:
You can group check boxes and assign them the same control name using the name attri-
bute. This allows multiple values associated with the same name to be chosen:
Check all symptoms that you are experiencing:
When this form is submitted to a script for processing, each check box that’s checked
returns a value associated with the name of the check box. If a check box isn’t checked,
neither the field name nor the value will be returned to the server—it’s as if the field
didn’t exist at all.
You may have noticed that when I applied labels to these check box elements, I put the
input tags inside the label tags. There’s a specific reason for doing so. When you asso-
ciate a label with a check box (or with a radio button, as you’ll see in the next section),
the browser enables you to check the box by clicking the label as well as by clicking the
button. That can make things a bit easier on your user.
In the examples thus far, I have tied labels to fields by putting the field id in the for
attribute of the label, but most designers don’t identify individual check box fields, and
the browser would not be able to figure out which check box the label applies to if you
pointed to the checkbox name. Instead, I put the input tag inside the label tag.
FIGURE 12.12
A check box field.