25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

178<br />

CHAPTER 7 ■ USING THE <strong>HTML</strong>5 FORMS API<br />

■ Note Autofocus can annoy users if they are not expecting a focus change. Many users utilize keystrokes for<br />

navigation, and switching focus to a form control subverts that ability. Use it only when it is a given that a form<br />

control should take all default keys.<br />

The list Attribute and the datalist Element<br />

The list attribute and datalist element combine to let a developer specify a list of possible values for<br />

an input. To use this combination:<br />

1. Create a datalist element in your document with its id set to a unique value.<br />

The datalist can be located anywhere in the document.<br />

2. Populate the datalist with as many option elements as needed to represent<br />

the full set of suggestions for values of a control. For example, a datalist<br />

representing e-mail contacts should contain all of the contact e-mail addresses<br />

as individual option children.<br />

<br />

<br />

<br />

<br />

3. Link the input element to the datalist by setting the list attribute to a value<br />

which is the id of the associated datalist.<br />

<br />

On a supporting browser, like Opera, this produces a customized list control like the following:<br />

The min and max Attributes<br />

As seen before in our example for , the min and max attributes allow a numerical<br />

input to be constrained to minimum and maximum values. One, both, or neither of these attributes can<br />

be provided as necessary, and the input control should adjust accordingly to increase or decrease the<br />

range of acceptable values. For example, to create a range control representing a level of confidence in<br />

ability from zero% to 100%, the following code could be used as follows:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!