<input> - text


HTML DOM Input Text Object


InputText object

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

Access the Input Text object

You can access <input> elements with type="text" via getElementById():

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

Try It! 

Tip: Again, you can access the Input Text object by looking up the form elements collection.

Create an InputText object

You can create <input> elements of type="text" with the document.createElement() method:

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

 Try It! 

Input Text Object Attributes

HTML5 new attribute.image.png


AttributeDescription
autocompleteimage.pngSets or returns the value of the autocomplete attribute of the text field
autofocusimage.pngSets or returns whether the text field automatically gets focus after page load
defaultValueSet or return the default value of the text field
disabledSets or returns whether the text field is disabled
formReturns a reference to the form object containing the text field
listimage.pngReturns a reference to a picklist object containing the text field
maxLengthSets or returns the maximum number of characters in a text field
nameSets or returns the name of the text field
patternimage.pngSets or returns the value of the pattern property of the text field
placeholderimage.pngSets or returns the value of the placeholder property of the text field
readOnlySets or returns whether the text field should be read-only
requiredimage.pngSets or returns whether the text field must be filled out before submitting a form
sizeSets or returns the value of the size property of the text field
typeReturns the form element type of the text field
valueSets or returns the value of the text field's value property

Input Text object methods

MethodDescription
blur()remove focus from text field
focus()Let the text field get the focus
select()Select the content of the text field

Standard Properties and Events

Input Text objects also support standard properties and events .


Related pages

HTML Tutorial: HTML Forms

HTML Reference Manual: HTML <input> Tag

HTML Reference Manual: HTML <input> type attribute