HTML DOM Input TextObject
Input Text Object
The Input Text object represents an HTML <input> element with type="text".
Access the Input Text Object
You can access the <input> element with type="text" by using getElementById():
var
x = document.getElementById("myText");
Try it Yourself
Tip:Similarly, you can look up the formelementscollection to access the Input Text object.
Create an Input Text Object
You can create an <input> element with type="text" using the document.createElement() method:
var x = document.createElement("INPUT");
x.setAttribute("type", "text"); Try it Yourself
x.setAttribute("type", "text"); Try it Yourself
Input Text Object Properties
= New in HTML5.
| Property | Description |
|---|---|
| autocomplete | Sets or returns the value of the autocomplete attribute of the text field |
| autofocus | Sets or returns whether the text field automatically gets focus after the page loads |
| defaultValue | Sets or returns the default value of the text field |
| disabled | Sets or returns whether the text field is disabled |
| form | Returns a reference to the form object that contains the text field |
| list | Returns a reference to the option list object that contains the text field |
| maxLength | Sets or returns the maximum number of characters in the text field |
| name | Sets or returns the name of the text field |
| pattern | Sets or returns the value of the pattern attribute of the text field |
| placeholder | Sets or returns the value of the placeholder attribute of the text field |
| readOnly | Sets or returns whether the text field should be read-only |
| required | Sets or returns whether the text field must be filled out before submitting a form |
| size | Sets or returns the value of the size attribute of the text field |
| type | Returns the form element type of the text field |
| value | Sets or returns the value of the value attribute of the text field |
Input Text Object Methods
| Method | Description |
|---|---|
| blur() | Removes focus from the text field |
| focus() | Gives focus to the text field |
| select() | Selects the contents of the text field |
Standard Properties and Events
The Input Text object also supports standardattributesandevents。
Related Pages
HTML Tutorial:HTML Forms
HTML Reference Manual:HTML <input> Tag
HTML Reference Manual:HTML <input> type Attribute
Other Extensions