HTML The Definitive Guide (109 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
13.23Mb size Format: txt, pdf, ePub

Chapter 10

Forms

 

10.9 Labeling and Grouping Form Elements
The common text and other content you may use to label and otherwise explain a form are static.

Other than by their visual relationship to the form's input areas, these labels and instructions otherwise are unassociated with the form control that they serve. Because of this, forms are not easily understood and navigable, particularly by people with impaired vision. Try it. Get a simple personal information HTML form on screen, close your eyes, and find the place to enter your name.

The HTML 4.0 standard introduces three new tags that make navigation of HTML forms easier for users, particularly those with disabilities. They include a way to group and caption regions of the form, and a way to individually label form controls. All are supposed to get special treatment by the browser, such as being rendered by a speech-synthesizer as well as specially displayed, and can be easily accessed from the user keyboard. That is, when browsers become HTML 4.0-compliant.

10.9.1 The

Use the

Function:

Creates a label for a form element

Attributes:

ACCESSKEY ONKEYDOWN

CLASS ONKEYPRESS

DIR ONKEYUP

FOR ONMOUSEDOWN

ID ONMOUSEMOVE

LANG ONMOUSEOUT

ONBLUR ONMOUSEOVER

ONCLICK ONMOUSEUP

ONDBLCLICK STYLE

ONFOCUS TITLE

End tag:

; never omitted

Contains:

label_contents

Used in:

form_content

10.9.1.1 Explicit and implicit associations
One or more labels get associated with a form control in one of two ways: implicitly by including the form control as contents of the label tag, or explicitly by naming the id of the target form control in the

For example:

The first label explicitly relates the text "Social Security Number:" with the form's Social Security Number text-input control (SocSecNum) since its for attribute's value is identical to the control's id, "SSN." The second label ("Date of birth") does not require a for attribute, nor does its related control require an id attribute, since they are implicitly joined by placing the tag within the

Be careful not to confuse the name and id attributes. The former creates a name for an element that is used by the server-side form processor; the latter creates a name that can be used by

10.9.1.2 Other label attributes

Labels also share many of the general display, access, and event-related HTML 4.0 tag attributes
described in section Section 10.8, "General Form Control Attributes". In addition to the standard

HTML 4.0 event attributes, labels also support the onfocus and onblur attributes.

10.9.2 Forming a Group

Beyond individual labels, you may group a set of form controls and label the group with the

and tags. Again, the HTML 4.0 standard's intention is to make forms more readily accessible by users, particularly those with disabilities. Grouping form controls into explicit sections gives you the opportunity to specially display and otherwise manage the form contents.

10.9.2.1 The

tag

Use the

tag to encapsulate a section of form contents, thereby creating a group of related form fields. A
does not have any required or unique attributes.


Function:

Group related elements within a form

Attributes:

CLASS ONKEYUP

DIR ONMOUSEDOWN

ID ONMOUSEMOVE

LANG ONMOUSEOUT

ONCLICK ONMOUSEOVER

ONDBLCLICK ONMOUSEUP

ONKEYDOWN STYLE

ONKEYPRESS TITLE

End tag:

; never omitted

Contains:

form_content

Used in:

form_content

When a group of form elements are placed within a

tag, the browser may display them in a special manner. This might include a special border, 3D effects, or even creating a subform to handle the elements. Since no browser currently supports fieldsets, we cannot predict nor provide an example of how they might be handled by a browser.

10.9.2.2 The tag

Use the tag to create a label for a fieldset in a form. The tag may appear only inside a

. Like

Other books

History of the Rain by Niall Williams
Dark Heart Surrender by Monroe, Lee
Interest by Kevin Gaughen
Heartland by Sara Walter Ellwood
Never Let You Go by Desmond Haas
Cold Fusion by Olivia Rigal