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 />

The right-hand side of the assignment expression extracts the current contents<br />

of the field and (with the help of the toUpperCase() method of the string object)<br />

converts the original string to all uppercase letters. The result of this operation is<br />

assigned to the value property of the field.<br />

The application of the this keyword in the previous examples may be confusing<br />

at first, but these examples represent the range of ways in which you can use such<br />

references effectively. Using this by itself as a parameter to an object’s event handler<br />

refers only to that single object — a text object in Listing 25-3. If you want to<br />

pass along a broader scope of objects that contain the current object, use the this<br />

keyword along with the outer object layer that you want. In Listing 25-2, I sent a reference<br />

to the entire form along by specifying this.form — meaning the form that<br />

contains “this” object, which is being defined in the line of HTML code.<br />

At the other end of the scale, you can use similar-looking syntax to specify a particular<br />

property of the this object. Thus, in the last example, I zeroed in on just the<br />

value property of the current object being defined — this.value. Although the<br />

formats of this.form and this.value appear the same, the fact that one is a reference<br />

to an object and the other just a value can influence the way your functions<br />

work. When you pass a reference to an object, the function can read and modify<br />

properties of that object (as well as invoke its functions); but when the parameter<br />

passed to a function is just a property value, you cannot modify that value without<br />

building a complete reference to the object and its value.<br />

Methods<br />

blur()<br />

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

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

Example<br />

The following statement invokes the blur() method on a text box named<br />

vanishText:<br />

document.forms[0].vanishText.blur()<br />

focus()<br />

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

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

Example<br />

See Listing 25-4 for an example of an application of the focus() method in concert<br />

with the select() method.<br />

363<br />

document.formObject.textObject.focus()

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

Saved successfully!

Ooh no, something went wrong!