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.

submit()<br />

Chapter 7 ✦ The Form and Related Objects (Chapter 23)<br />

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

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

Example<br />

Consult Listing 23-3 for an example of using the submit() method from outside<br />

of a form.<br />

Event handlers<br />

onReset<br />

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

Compatibility ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Listing 23-4 demonstrates one way to prevent accidental form resets or submissions.<br />

Using standard Reset and Submit buttons as interface elements, the <br />

object definition includes both event handlers. Each event handler calls its own<br />

function that offers a choice for users. Notice how each event handler includes the<br />

word return and takes advantage of the Boolean values that come back from the<br />

confirm() method dialog boxes in both functions.<br />

Listing 23-4: The onReset and onSubmit Event Handlers<br />

<br />

<br />

Submit and Reset Confirmation<br />

<br />

function allowReset() {<br />

return window.confirm(“Go ahead and clear the form?”)<br />

}<br />

function allowSend() {<br />

return window.confirm(“Go ahead and mail this info?”)<br />

}<br />

<br />

<br />

<br />

<br />

Continued<br />

341<br />

FORM.onReset

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

Saved successfully!

Ooh no, something went wrong!