15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

336<br />

FORM.elements<br />

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

✦ While batch form validations are shown in several places throughout the<br />

<strong>JavaScript</strong> <strong>Bible</strong>, Listing 23-4 demonstrates how both the onReset and<br />

onSubmit event handlers, in concert with the window.confirm() method, let<br />

scripts permit or prevent a form from being reset or submitted.<br />

FORM Object<br />

Properties<br />

action<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

The following statement assigns a mailto: URL to the first form of a page:<br />

document.forms[0].action = “mailto:jdoe@giantco.com”<br />

elements<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

The document in Listing 23-2 demonstrates a practical use of the elements<br />

property. A form contains four fields and some other elements mixed in between<br />

(see Figure 7-1). The first part of the function that acts on these items repeats<br />

through all the elements in the form to find out which ones are text box objects and<br />

which text box objects are empty. Notice how I use the type property to separate<br />

text box objects from the rest, even when radio buttons appear amid the fields. If<br />

one field has nothing in it, I alert the user and use that same index value to place<br />

the insertion point at the field with the field’s focus() method.

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

Saved successfully!

Ooh no, something went wrong!