O'Reilly logo

JavaScript® Bible, Seventh Edition by Paul Novitski, Danny Goodman, Tia Gustaff Rayl, 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 36. 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 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 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.

Text Input Object

For HTML element properties, methods, and event handlers, see Chapter 26, "Generic HTML Element Objects."

Properties

Methods

Event Handlers

defaultValue

select()

onafterupdate

form

blur()

onbeforeupdate ...

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