HTML DOM Input Text Object
The Input Text object
The Input Text object represents an HTML element with type="text" .
Access the Input Text Object
You can access the type="text" using getElementById() element:
var x = document.getElementById("myText");
Try it
Tip: Similarly, you can look up the form elements collection to access the Input Text object.
Create the Input Text Object
You can use the document.createElement() method to create a type="text" element:
var x = document.createElement("INPUT");
x.setAttribute("type", "text");
Try it
Input Text Object Properties
= New attribute 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 options 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 content of the text field |
Standard properties and events
The Input Text object also supports standard property and Events.
Related pages
HTML Tutorial: HTML Forms
HTML Reference Manual: HTML tag
HTML Reference Manual: HTML type Attribute