Javascript DOM HTML Textarea maxLength Property set

Introduction

Change the maximum number of characters allowed in a text area:

document.getElementById("myTextarea").maxLength = "4";

Click the button to set the maximum number of characters allowed in the text area to "4".

View in separate window

<!DOCTYPE html>
<html>
<body>

Address:<br>
<textarea id="myTextarea">
</textarea>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  ww  w.  j a  v  a 2  s.  c om
  document.getElementById("myTextarea").maxLength = "4";
  document.getElementById("demo").innerHTML = "Maximum number of characters allowed in the text area is now 4.";
}
</script>

</body>
</html>



PreviousNext

Related