The following sets a keydown event, preventing further input when a condition is achieved.
<textarea rows="5" cols="30" onkeydown="return checkLength(this)"></textarea>
<script type="text/javascript">
var maxLength = 30;
function checkLength(elem) {
if (elem.value.length == maxLength) {
return false;
}
return true;
}
</script>
IN the above I don't understand this part: onkeydown="return checkLength(this)" . How does setting onkeydown to false prevent further input into the textarea ?
Also can the same be set using addeventlistener() ? If so how ?
Thanks