0

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

Edited by kutchbhi: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Troy III
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.