IN THIS CHAPTER
Capturing and modifying text field contents
Triggering action by entering text
Capturing individual keystroke events
The document object model for forms includes four text-related user interface objects—
text, password, and
hidden input element objects, plus the
textarea element object. All four of these objects are used for entry, display, or temporary storage of text data. Although all these objects can have text placed in them by default as the page loads, scripts can also modify the contents of these objects. Importantly, all but the
hidden objects retain their user- or script-modified content during a soft reload (for example, clicking the Reload button) in Mozilla and Internet Explorer;
hidden objects revert to their default values on all reloads.
A more obvious difference between the
hidden object and the rest is that its invisibility removes it from the realm of user events and actions. Therefore, the range of scripted possibilities is much smaller for the
The persistence of
textarea object data through reloads (and window resizes), however, is neither reliable enough nor consistent enough across all modern browsers to be used in lieu of a temporary cookie. This is a change from past implementations.
For HTML element properties, methods, and event handlers, see Chapter 26, "Generic HTML Element Objects."