Javascript examples for DOM HTML Element:Input Text
Input Text maxLength Property - Set the maximum number of characters allowed in a 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 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>