Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

334 LESSON 12: Designing Forms


If you include a name attribute for a Submit button, the value that you assign to the field
is sent to the server if the user clicks on that Submit button. This enables you to take dif-
ferent actions based on which Submit button the user clicks, if you have more than one.
For example, you could create two Submit buttons, both with the name attribute set to
“action". The first might have a value of “edit" and the second a value of “delete". In
your script, you could test the value associated with that field to determine what the user
wanted to do when he submitted the form.

Creating Reset Buttons


Reset buttons set all the form controls to their default values. These are the values
included in the value attributes of each field in the form (or in the case of selectable
fields, the values that are preselected). As with the Submit button, you can change the
label of a Reset button to one of your own choosing by using the value attribute, like
this:
<input type="reset" value="Clear Form" >

NOTE Your forms can contain more than one Submit button.

Reset buttons can be a source of some confusion for users.
Unless you have a really good reason to include them on your
forms, you should probably just avoid using them. If your form is
large and the user clicks the Reset button when he means to click
the Submit button, he isn’t going to be very pleased with having to
go back and reenter all of his data.

CAUTION

Creating Check Box Controls


Check boxes are fields that can be set to two states: on and off (see Figure 12.12). To
create a check box, set the input tag’s type attribute to checkbox. The name attribute is
also required, as shown in the following example:

Input ▼
<label>Check to receive SPAM email <input type="checkbox" id="spam"></label>
Free download pdf