O'Reilly logo

JavaScript® Bible, Sixth Edition by Danny Goodman, Brendan Eich, Michael Morrison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required