Posted By


jlvallelonga on 03/24/09

Tagged


Statistics


Viewed 651 times
Favorited by 0 user(s)

getCharacterPressed


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.