Posted By

chrisdpratt on 09/21/09


Tagged

events keyboard onkeypress onkeyup onkeydown


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


Detecting Only Actual Text Changes onkeydown/onkeyup/onkeypress in JavaScript


 / Published in: JavaScript
 

The following script will allow only keys that effect actual text changes in input/textareas (character keys, spacebar, backspace and delete). Any other key type will tell whatever function is handling the event to return and not continue on. As a result, this should be place before the actual processing portion of the function.

  1. if (
  2. (e.keyCode != 32) && // not spacebar
  3. (e.keyCode != 8) && // not backspace
  4. (e.keyCode != 46) && // not delete
  5. ((e.keyCode < 48) || (e.keyCode > 90)) // non-character
  6. ) return true;

Report this snippet  

You need to login to post a comment.