HTML The Definitive Guide (108 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

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

Chapter 10

Forms

 

10.8 General Form Control Attributes

The many form control tags contain common attributes that, like most other HTML 4.0 tags, generally serve to label, set up the display, extend the text language, and make the tag extensible programmatically.

10.8.1 The id and title Attributes

The id attribute, like most other HTML 4.0 standard tags, lets you attach a unique string label to the form control and its contents for reference by programs (applets) and hyperlinks. This name is distinct from the name assigned to a control element with the name attribute. Names assigned with the id attribute are not passed to the server when the form is processed.

The title attribute is similar to id in that it uses a quote-enclosed string value to label the form control. However, it entitles only the form segment; its value cannot be used in an applet reference or hyperlink. Browsers may use the title as pop-up help for the user, or in nonvisual presentation of the
form. [The id attribute, 4.1.1.4]
[The title attribute, 4.1.1.5]

10.8.2 The event Attributes

Like most other elements in an HTML 4.0 standard document, most of the form controls support a number of user mouse and keyboard event-related attributes that the HTML 4.0-compliant browser will recognize and let you specially process with an applet, such as a JavaScript program. We describe
the majority of these events in detail in Chapter 13, Executable Content.

10.8.3 The class, style, lang, and dir Attributes
The style attribute for the various form controls creates an inline style for the elements enclosed by the tag, overriding any other style rule in effect. The class attribute lets you format the content according to a predefined class of the


tag; its value is the name of that class. [Inline Styles:

The style Attribute, 9.1.1]
[Style Classes, 9.2.4]

The lang attribute lets you specify the language used within a control, accepting as its value any of the ISO standard two-character language abbreviations, including an optional language modifier. For example, adding lang=en-UK tells the browser that the list is in English ("en") as spoken and written in the United Kingdom (UK). Presumably, the browser may make layout or typographic decisions based upon your language choice.
[The lang attribute, 3.5.1.2]

Similarly, the dir attribute tells the browser which direction to display the control contents, from left to right (dir=ltr) like English or French, or from right to left (dir=rtl), such as with Hebrew or
Chinese. [The dir attribute, 3.5.1.1]

The dir and lang attributes are supported by the popular browsers, even though there are no behaviors defined for any specific language.

10.8.4 The notab, tabindex, and taborder Attributes
By default, every element (except hidden elements) is part of the form's tab order. As the user presses the Tab key, the browser shifts the input focus from element to element in the form. For most browsers, the tabbing order of the elements matches the order of the elements within the tag.

With HTML 4.0's tabindex attribute, you can change the order and the position of those elements within the tab order.

To reposition an element within the tab order, set the value of the attribute to the element's desired position in the tab order, with the first element in the order being number one. If you really want to change a form's tab order, we suggest you include the tabindex attribute with every element in the form, with an appropriate value for each element. In this way, you'll be sure to place every element explicitly in the tab order, and there will be no surprises when the user tabs through the form.

The value of the tabindex attribute is a positive integer indicating the position of the tagged contents in the overall tab sequence for the document. The tabbing order begins with elements with explicit tabindex values, starting from the lowest to the highest numbers. Same-valued tags get tab-selected in the order in which they appear in the document. All other tabable tags, such as the various form controls and hyperlinks, are the last to get tabbed, in the order in which they appear in the document. To exclude an element from the tab order, set the value of tabindex to zero. The element will be skipped when the user tabs around the form.

Internet Explorer introduced the concept of taborder management with its proprietary taborder and notab attributes. The taborder attribute functions exactly like the HTML 4.0 tabindex attribute, while notab is equivalent to tabindex=0. In general, we suggest using the tabindex attribute instead of taborder, ensuring that your documents, while not tab-sensitive with the current browsers, will most certainly be so with future releases.

10.8.5 The accesskey Attribute

Many user interfaces promote the idea of shortcut keys, short sequences of keystrokes that gives you quick access to an element in the user interface. HTML 4.0 provides support for this capability with the accesskey attribute. The value of the accesskey attribute is a single character that, when pressed in conjunction with some other special key, causes focus to shift immediately to the associated form element. This special key varies with each user interface: Windows users might press the Alt key, while Unix users would press Meta, for example.

For example, adding accesskey=T to a