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.

Text-Related<br />

Form Objects<br />

(Chapter 25)<br />

When your page needs input from visitors beyond<br />

“yes” or “no” answers, text fields are the interface<br />

elements that provide the blank spaces. Whether you specify<br />

the one-line INPUT element or the multi-line TEXTAREA element,<br />

this is where visitors can not only express themselves,<br />

but also enter information in formats that might cause your<br />

carefully constructed back-end database to go haywire. More<br />

often than not, it is the text box that benefits most from clientside<br />

form validation.<br />

Despite the fact that the primary user action in a text box<br />

is typing, keyboard events became available to scripters only<br />

starting with the version 4 browsers from both Microsoft and<br />

Netscape. But they arrived fully formed, with a suite of events<br />

for the downstroke, upstroke, and complete press-and-release<br />

action of typing a character. From there, the event object<br />

takes over to help scripts uncover the character code and<br />

whether the user held down any modifier keys while typing<br />

the character. You can find examples of this kind of event handling<br />

in the examples for Chapters 1 and 13 of this book.<br />

Text boxes are not always as scriptable as you might like<br />

them to be. Modern browsers can apply style sheets to adjust<br />

font characteristics of the complete text box, but you cannot,<br />

say, set some of the words inside a text box to bold. Even<br />

something as common (in other programs) as having the text<br />

insertion pointer automatically plant itself at the end of existing<br />

text is possible so far only in IE4+/Windows via the<br />

TEXTAREA’s createTextRange() method and associated<br />

TextRange object methods (see TextRange object examples<br />

in Chapter 5 of this book). The moral of the story is to keep<br />

your expectations for the powers of text fields at moderate<br />

levels.<br />

9<br />

C H A P T E R<br />

✦ ✦ ✦ ✦<br />

In This Chapter<br />

Capturing and<br />

modifying text field<br />

contents<br />

Triggering action and<br />

entering text<br />

Giving focus to a text<br />

field and selecting its<br />

contents<br />

✦ ✦ ✦ ✦

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

Saved successfully!

Ooh no, something went wrong!