Chapter 23. Text-Related Form Objects

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 of 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 hidden object.

The persistence of text and textarea object data through reloads (and window resizes), however, is not 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.

Text Input Object

For HTML element properties, methods, and event handlers, see Chapter 15.

Properties

Methods

Event Handlers

defaultValue

select()

onafterupdate

form

 

onbeforeupdate

maxLength

 

onchange

name

 

onerrorupdate ...

Get JavaScript® Bible, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.