HTML DOM Input Text Object

Input Text object

The Input Text object represents the HTML <input> element with type="text".

Access Input Text object

You can use getElementById() to access the <input> element with type="text":

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

Try it yourself

Tip:You can also search the form by elements collection To access <input type="text">.

Create Input Text object

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

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

Try it yourself

Input Text object properties

Attributes Description
autocomplete Set or return the autocomplete attribute value of the text field.
autofocus Set or return whether the text field should automatically receive focus when the page is loaded.
defaultValue Set or return the default value of the text field.
disabled Set or return whether the text field is disabled.
form Return a reference to the form containing the text field.
list Return a reference to the data list containing the text field.
maxLength Set or return the maxlength attribute value of the text field.
name Set or return the name attribute value of the text field.
pattern Set or return the pattern attribute value of the text field.
placeholder Set or return the placeholder attribute value of the text field.
readOnly Set or return whether the text field is read-only.
required Set or return whether the text field must be filled out before submitting the form.
size Set or return the size attribute value of the text field.
type Return the type of form element the text field is.
value Set or return the value attribute of the text field.

Input Text object methods

Method Description
blur() Remove focus from the text field.
focus() Give focus to the text field.
select() Select the content of the text field.

Standard attributes and events

The Input Text object supports both standardsAttributesandEvents.

Related pages

HTML tutorial:HTML form

HTML reference manual:HTML <input> tag

HTML reference manual:HTML <input> type attribute