Input Text maxLength Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

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

Return Value

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials