JavaScript listener, "keypress" doesn't detect backspace?

Skizit picture Skizit · Jan 30, 2011 · Viewed 147.1k times · Source

I'm using a keypress listener eg..

addEventListener("keypress", function(event){

}

However, this doesn't seem to detect a backspace which erases text...

Is there a different listener I can use to detect this?

Answer

Kris Ivanov picture Kris Ivanov · Jan 30, 2011

KeyPress event is invoked only for character (printable) keys, KeyDown event is raised for all including nonprintable such as Control, Shift, Alt, BackSpace, etc.

UPDATE:

The keypress event is fired when a key is pressed down and that key normally produces a character value

Reference.