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

(singke) #1
ptg16476052

338 LESSON 12: Designing Forms


button, set the type attribute to button. Figure 12.15 shows a button that calls a function
when it is pressed. Use the following code to create a button:

Input ▼
<input type="button" id="verify" value="verify" onclick="verifydata()">

Output ▼


This example creates a button that runs a function called verifydata when it’s clicked.
You provide the label that appears on the button with the value attribute of Verify Data.
Unlike Submit buttons, regular buttons don’t submit the form when they’re clicked. I
explain the onclick attribute when you get to Lesson 17, “Introducing JavaScript.”

Hidden Form Fields


Hidden form fields are used when you want to embed data in a page that shouldn’t be
seen or modified by the user. The name and value pair associated with a hidden form
field will be submitted along with the rest of the contents of the form when the form is
submitted. To create such a field, set the field’s type to hidden and be sure to include
both the name and the value attributes in your <input> tag. Here’s an example:
<input type="hidden" id="uid" value="1402">
Hidden form fields are generally used when data identifying the user needs to be included
in a form. For example, suppose you’ve created a form that allows a user to edit the name
and address associated with her bank account. Because the user can change her name and
address, the data she submits can’t be used to look up her account after she submits the
form, plus there might be multiple accounts associated with one name and address. You
can include the account number as a hidden field on the form so that the program on the
server knows which account to update when the form is submitted.

FIGURE 12.15
A button element
on a web page.
Free download pdf