DekGenius.com
Team LiB   Previous Section   Next Section
Textarea a multiline text input area

Availability

JavaScript 1.0; enhanced in JavaScript 1.1

Inherits from/Overrides

Inherits from Input, HTMLElement

Synopsis

form.name
form.elements[i]

Properties

Textarea inherits the properties of Input and HTMLElement and defines or overrides the following:

value

A read/write string property. The initial value of this property is the same as the defaultValue property: the plain text (i.e., without any HTML tags) that appears between the <textarea> and </textarea> tags. When the user types characters into the Textarea object, the value property is updated to match the user's input. If you set the value property explicitly, the string you specify is displayed in the Textarea object. This value property contains the string that is sent to the server when the form is submitted.

Methods

Textarea inherits the methods of Input and HTMLElement.

Event Handlers

Textarea inherits the event handlers of Input and HTMLElement and defines or overrides the following:

onchange

Invoked when the user changes the value in the Textarea element and moves the keyboard focus elsewhere. This event handler is not invoked for every keystroke in the Textarea element, but only when the user completes an edit.

HTML Syntax

A Textarea element is created with standard HTML <textarea> and </textarea> tags:

<form>
    ...
  <textarea
    [ name="name" ]         // A name that can be used to refer to this element
    [ rows="integer" ]      // How many lines tall the element is
    [ cols="integer" ]      // How many characters wide the element is
    [ onchange="handler" ]  // The onchange(  ) event handler
  >
    plain_text              // The initial text; specifies defaultValue
  </textarea>
    ...
</form>

Description

The Textarea element represents a text input field in a form. The name attribute specifies a name for the element. This is mandatory if the form is to be submitted, and it also provides a convenient way to refer to the Textarea element from JavaScript code. The cols attribute specifies the width, in characters, of the element as it appears on the screen, and the rows attribute specifies the height, in lines of text, of the element. The wrap attribute specifies how long lines should be handled: the value off specifies that they should be left as-is, the value virtual specifies that they should be displayed with line breaks but transmitted without them, and the value physical specifies that they should be displayed and transmitted with line breaks inserted.

In addition to these HTML attributes, value is the main property of interest for the Textarea element. You can read this property to obtain the user's input or set it to display arbitrary (unformatted) text in the Textarea. The initial value of the value property (and the permanent value of the defaultValue property) is the text that appears between the <textarea> and </textarea> tags.

Note that the Textarea object is a kind of Input object and inherits from Input, despite the fact that Textarea objects are not created with HTML <input> tags.

Usage

If you need only a single line of input text, use the Text element. If the text to be input is sensitive information, such as a password, use the Password element.

See Also

Form, HTMLElement, Input, Password, Text; HTMLTextAreaElement in the DOM reference section

    Team LiB   Previous Section   Next Section