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

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>

1. IN the above I don't understand this part: onkeydown="return checkLength(this)" .
2. How does setting onkeydown to false prevent further input into the textarea ?
3. Also can the same be set using addeventlistener() ? If so how ?

Thanks

1.There's no need for the "return" statement on the event assignment value checkLength function has enough of them returns.
2. Assigning 'false' to the value of any 'event' nullifies it.
3. Of course.