
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input Text maxLength Property
The HTML DOM Input Text maxLength property is used for setting or returning the maxlength attribute of the input text field. The maxLength property specifies the maximum number of characters you can type in a text field.
Syntax
Following is the syntax for −
Setting the maxLength property −
textObject.maxLength = integer
Here, integer specifies the maximum number of characters that can be typed in the text field.
Example
Let us look at an example for the maxLength property −
<!DOCTYPE html> <html> <body> <h1>Input Text maxLength Property</h1> USERNAME: <input type="text" id="USR" maxLength="5"> <p>Increase the maximum number of characters to be entered for the above field by clicking below button</p> <button onclick="changeMax()">CHANGE LENGTH</button> <p id="Sample"></p> <script> function changeMax() { document.getElementById("USR").maxLength = "15"; document.getElementById("Sample").innerHTML = "Maximum number of characters are now increased to 15"; } </script> </body> </html>
Output
This will produce the following output. Only 5 characters are allowed since we have set maxLength 5 −
On clicking the CHANGE LENGTH button −
- Related Articles
- HTML DOM Input Email maxLength Property
- HTML DOM Input URL maxLength Property
- HTML DOM Input Password maxLength Property
- HTML DOM Input Search maxLength Property
- HTML DOM Textarea maxLength Property
- HTML DOM Input Text size Property
- HTML DOM Input Text type Property
- HTML DOM Input Text value Property
- HTML DOM Input Text autocomplete Property
- HTML DOM Input Text autofocus Property
- HTML DOM Input Text defaultValue Property
- HTML DOM Input Text disabled Property
- HTML DOM Input Text form Property
- HTML DOM Input Text name Property
- HTML DOM Input Text pattern property

Advertisements