Easy Tutorial
❮ Prop Radio Type Prop Link Rel ❯

HTML DOM Textarea Object


Textarea Object

The Textarea object represents a text field (textarea) in an HTML form.

Each <textarea> tag in an HTML form creates a Textarea object.

For HTML textarea content, refer to: HTML <textarea> Tag.

You can access a Textarea object by indexing the elements array of the corresponding form, or by using the getElementById() method.

Example

Retrieve the text content of a textarea:

var x = document.getElementById("myTextarea").value;

Tip: You can also retrieve the content of a textarea by finding the <textarea> in the form collection's elements.


Creating a Textarea Object

You can create a <textarea> element using the document.createElement() method:

Example

Create a textarea element:

var x = document.createElement("TEXTAREA");

Textarea Object Properties

Property Description W3C
autofocus Sets or returns whether the textarea should automatically get focus when the page loads. Yes
cols Sets or returns the width of the textarea. Yes
defaultValue Sets or returns the initial content of the text area. Yes
disabled Sets or returns whether the textarea should be disabled. Yes
form Returns a reference to the form that contains the textarea. Yes
maxLength Sets the maximum number of characters that can be entered in the textarea element. Yes
name Sets or returns the name of the textarea. Yes
placeholder Sets or returns the value of the placeholder attribute. Yes
readOnly Sets or returns whether the textarea should be read-only. Yes
require Sets or returns whether the textarea must be filled out. Yes
rows Sets or returns the height of the textarea. Yes
type Returns the form type of the text box. Yes
value Sets or returns the text in the textarea. Yes

Textarea Object Methods

Method Description W3C
select() Selects the text in the textarea. Yes

Standard Attributes and Events

The Textarea object also supports standard attributes and events.

❮ Prop Radio Type Prop Link Rel ❯