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.

Chapter 9 ✦ Text-Related Form Objects (Chapter 25)<br />

want to reset only a subset of fields in a form, follow the example button and function<br />

in Listing 25-1.<br />

Listing 25-1: Resetting a Text Object to Default Value<br />

<br />

<br />

Text Object DefaultValue<br />

<br />

function upperMe(field) {<br />

field.value = field.value.toUpperCase()<br />

}<br />

function resetField(form) {<br />

form.converter.value = form.converter.defaultValue<br />

}<br />

<br />

<br />

<br />

<br />

Enter lowercase letters for conversion to uppercase: <br />

<br />

<br />

<br />

<br />

form<br />

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

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

Example<br />

The following function fragment receives a reference to a text element as the<br />

parameter. The text element reference is needed to decide which branch to follow;<br />

then the form is submitted.<br />

function setAction(fld) {<br />

if (fld.value.indexOf(“@”) != -1) {<br />

fld.form.action = “mailto:” + fld.value<br />

} else {<br />

fld.form.action = “cgi-bin/normal.pl”<br />

}<br />

fld.form.submit()<br />

}<br />

359<br />

document.formObject.textObject.form

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

Saved successfully!

Ooh no, something went wrong!