Posted By

jlvallelonga on 03/24/09


Tagged

get event character code key pressed backspace


Versions (?)

getCharacterPressed


 / Published in: JavaScript
 

send in an event it returns the key that you pressed if it was alphanumeric or backspace otherwise it returns "-1" use with getKeyCode and isAlphaNumeric

  1. function getCharacterPressed(e) {
  2. code = getKeyCode(e);
  3. keychar = "-1";
  4. if (isAlphaNumeric(code))
  5. keychar = String.fromCharCode(code);
  6. if (code == 8)
  7. keychar = "backspace";
  8. return keychar;
  9. }

Report this snippet  

You need to login to post a comment.