Input Text maxLength Property - Set the maximum number of characters allowed in a text field: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Input Text maxLength Property - Set the maximum number of characters allowed in a 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  ww  w  .ja va 2 s  .  c o m*/
    document.getElementById("myText").maxLength = "4";
    document.getElementById("demo").innerHTML = "Maximum number of characters allowed in the text field is now 4.";
}
</script>

</body>
</html>

Related Tutorials