HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM Text Object


Text Object

The Text object represents an HTML <input type="text"> element.

Access a Text Object

You can access an <input type="text"> element by using getElementById():

var x = document.getElementById("myText"); Try it

Tip: You can also access a Text object by searching through the elements collection of a form.

Create a Text Object

You can create an <input type="text"> element by using the document.createElement() method:

var x = document.createElement("INPUT");
x.setAttribute("type", "text"); Try it

Text Object Properties

Property Description
defaultValue Sets or returns the default value of a text field
disabled Sets or returns whether the text field is disabled, or not
form Returns a reference to the form that contains the text field
maxLength Sets or returns the value of the maxlength attribute of a text field
name Sets or returns the value of the name attribute of a text field
readOnly Sets or returns whether a text field is read-only, or not
size Sets or returns the value of the size attribute of a text field
type Returns which type of form element a text field is
value Sets or returns the value of the value attribute of the text field

Text Object Methods

Method Description
select() Selects the content of a text field

Standard Properties and Events

The Text object also supports the standard properties and events.


Related Pages

HTML tutorial: HTML Forms

HTML reference: HTML <input> tag

HTML reference: HTML <input> type attribute



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE