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.

document.forms[0].inspector.readOnly = true<br />

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

While existing text in the box is selectable (and therefore can be copied into the<br />

clipboard), it cannot be modified or removed.<br />

size<br />

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

Compatibility ✓ ✓ ✓ ✓<br />

Example<br />

Resize the bottom text box of The Evaluator (Chapter 13 in <strong>JavaScript</strong> <strong>Bible</strong>) by<br />

entering the following statements into the top text box:<br />

document.forms[0].inspector.size = 20<br />

document.forms[0].inspector.size = 400<br />

Reload the page to return the size back to normal (or set the value to 80).<br />

value<br />

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

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

Example<br />

As a demonstration of how to retrieve and assign values to a text object, Listing<br />

25-2 shows how the action in an onChange event handler is triggered. Enter any<br />

lowercase letters into the field and click out of the field. I pass a reference to the<br />

entire form object as a parameter to the event handler. The function extracts the<br />

value, converts it to uppercase (using one of the <strong>JavaScript</strong> string object methods),<br />

and assigns it back to the same field in that form.<br />

Listing 25-2: Getting and Setting a Text Object’s Value<br />

<br />

<br />

Text Object Value<br />

<br />

function upperMe(form) {<br />

inputStr = form.converter.value<br />

form.converter.value = inputStr.toUpperCase()<br />

}<br />

<br />

<br />

Continued<br />

361<br />

document.formObject.textObject.value

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

Saved successfully!

Ooh no, something went wrong!