HTML and CSS Reference
In-Depth Information
Table 9.11 Common 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.
Alphanumeric, no spaces,
begins with a letter
Provides a unique identifier for the form element.
id
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.
value
FAQ
Why use both the name and the id attributes on form controls?
The reason both attributes are used is for forward and backward compatibility with different
versions of HTML and XHTML.
The name attribute 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 name attribute for a
form element should be unique for that form.
The id attribute 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
id attribute to be compatible with CSS and XHTML in the future.
Forward thinking Web developers use both the name and id attributes on their form elements.
Typically, the values assigned to the name and id attribute on a particular form element are the
same.
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.
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.
 
Search WWH ::




Custom Search