15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

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.

46 <strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

elementObject.tabIndex<br />

When you load the page, the default tabbing order for the lab form control elements<br />

(default setting of zero) takes charge. If you start pressing the Tab key, the<br />

precise results at first depend on the browser you use. In IE, the Address field is<br />

first selected; next the Tab sequence gives focus to the window (or frame, if this<br />

page were in a frameset); finally the tabbing reaches the lab form. Continue pressing<br />

the Tab key and watch how the browser assigns focus to each of the element<br />

types. In NN6, however, you must click anywhere on the content to get the Tab key<br />

to start working on form controls.<br />

The sample script inverts the tabbing sequence with the help of a for loop that<br />

initializes two variables that work in opposite directions as the looping progresses.<br />

This gives the last element the lowest tabIndex value. The skip2() function simply<br />

sets the tabIndex property of the second text box to -1, removing it from the<br />

tabbing entirely (IE only). Notice, however, that you can click in the field and still<br />

enter text. (See the disabled property earlier in this chapter to see how to prevent<br />

field editing.) NN6 does not provide a tabIndex property setting that forces the<br />

browser to skip over a form control. You should disable the control instead.<br />

Listing 15-16: Controlling the tabIndex Property<br />

<br />

<br />

tabIndex Property<br />

<br />

function invert() {<br />

var form = document.lab<br />

for (var i = 0, j = form.elements.length; i < form.elements.length;<br />

i++, j--) {<br />

form.elements[i].tabIndex = j<br />

}<br />

}<br />

function skip2() {<br />

document.lab.text2.tabIndex = -1<br />

}<br />

function resetTab() {<br />

var form = document.lab<br />

for (var i = 0; i < form.elements.length; i++) {<br />

form.elements[i].tabIndex = 0<br />

}<br />

}<br />

<br />

<br />

<br />

tabIndex Property Lab<br />

<br />

<br />

Text box no. 1: <br />

Text box no. 2: <br />

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

Saved successfully!

Ooh no, something went wrong!