views:

54

answers:

3

Hey,

How can I cancel the keydown of a button on the keyboard in an HTML page.

Thanks

+2  A: 

Handle the onkeydown event and return false;

SLaks
+2  A: 

Try this

<input type="button" onkeydown="return false;" />
Antony Highsky
+2  A: 

It's somewhat more complicated than described so far, see Quirksmode.org:

You cannot prevent the default onkeydown in Opera.

In Opera, use onkeypress instead.

Marcel Korpel
Correct. I think Jan Wolter's article at http://unixpapa.com/js/key.html is the definitive work on JavaScript key events.
Tim Down