Javascript examples for DOM HTML Element:Input Text
The maxLength property sets or gets the maxlength attribute of a text field, which sets the maximum number of characters allowed in a text field.
Set the maxLength property with the following Values
Value | Description |
---|---|
number | Sets the maximum number of characters allowed in the text field |
A Number, representing the maximum number of characters allowed in the text field
The following code shows how to get the maximum number of characters allowed in a specific text field:
<!DOCTYPE html> <html> <body> Name: <input type="text" id="myText"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w. j a v a2s . com*/ var v = document.getElementById("myText").maxLength; document.getElementById("demo").innerHTML = v; } </script> </body> </html>