FAQ
9.2 XHTML—Using Forms^365
Table 9.11Common hidden attributes
Common
Attributes Values Usage
type hidden Configures the hidden form element.
name Alphanumeric, no spaces,
begins with a letter
Names the form element so that it can be easily accessed by client-
side scripting languages (such as JavaScript) or by server-side pro-
cessing. The name should be unique.
id Alphanumeric, no spaces,
begins with a letter
Provides a unique identifier for the form element.
value Text or numeric
characters
Assigns a value to the hidden control. This value can be accessed by
client-side scripting languages and by server-side processing.
Why use both the nameand the idattributes on form controls?
The reason both attributes are used is for forward and backward compatibility with different
versions of HTML and XHTML.
Thenameattribute is supported by both HTML and XHTML. It is used to name the form ele-
ment so that it can be easily accessed by client-side scripting languages such as JavaScript or
by server-side processing languages such as PHP. The value given to a nameattribute for a
form element should be unique for that form.
Theidattribute is included for use with CSS and is supported by XHTML. The value of the id
attribute should be unique to the entire Web page document that contains the form. Use the
idattribute to be compatible with CSS and XHTML in the future.
Forward thinking Web developers use both the nameandidattributes on their form elements.
Typically, the values assigned to the nameandidattribute on a particular form element are the
same.
HANDS-ON PRACTICE 9.2
In this Hands-On Practice you will modify the form you created in Hands-On Practice
9.1 (see Figure 9.3). Recall that the purpose of the form is to allow Web page visitors to
request that a company representative contacts them. You will modify the form to
include a reset button and to accept the customer’s name, phone number, and a ques-
tion or comment in addition to the e-mail address. This modified form is shown in
Figure 9.15.
As you have seen, there are a number of form controls, each with a specific purpose.
This would be a good time to visit a few Web sites and examine how they use forms.
Take a look at sites such as http://yahoo.com, http://amazon.com, http://ebay.com, or
one of your favorites and identify when and how they use forms and form controls.