[ACCEPTED]-Javascript: addEventListener with onkeydown doesn't seem to work-javascript

Accepted answer
Score: 46

The event type should be "keydown", notice that 3 you don't need the on prefix:

element.addEventListener("keydown", keyDownTextField, false);

Note also that 2 you should get the keyCode from the event object 1 in your handler:

function keyDownTextField (e) {
  var keyCode = e.keyCode;

Check an example here.

More Related questions