25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

174<br />

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

gives a convenient way to pick a suitable value for age-restricted material. In the latest Opera browser, it<br />

displays as follows:<br />

Unfortunately, the range input itself doesn’t display a numerical representation of the browser.<br />

Moreover, without one, it is practically impossible for the user to know what the currently selected value<br />

happens to be. To fix this, one can easily add an onchange handler to update a display field based on<br />

changes to the current range value as shown in Listing 7-1.<br />

Listing 7-1. onchange handler to update a display field<br />

<br />

function showValue(newVal) {<br />

document.getElementById("ageDisplay").inner<strong>HTML</strong> = newVal;<br />

}<br />

<br />

Age<br />

<br />

18<br />

This gives a nice display to our range input, as follows:<br />

Opera and the WebKit-based browsers—Safari and Chrome—have now added support for the type<br />

range element. Firefox support is planned, but not yet scheduled as of this writing. Firefox will fall back<br />

to a simple text element when presented with a range input type.<br />

HERE BE DRAGONS<br />

Brian says: “The phrase ‘Here be dragons’ is said to have been used in history to denote dangerous areas<br />

on maps where unknown perils lurk. The same could be said for the following form elements. Although<br />

they are specified, and have been for lengths of time now, most are lacking in actual implementation.<br />

As such, expect large changes between now and the time that browser developers have had a chance to<br />

play with the designs, smooth the rough edges, and respond with feedback and changes. Rather than rely<br />

on the following components as inevitable, take them as a sign of the direction in which <strong>HTML</strong>5 forms are<br />

moving. If you attempt to use them today, the risk you take is your own…”<br />

Additional form elements which are planned, but not widely supported yet include the ones listed in<br />

Table 7-3:

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

Saved successfully!

Ooh no, something went wrong!