hi,
I have written a javascript on a button which blocks the keypress or keydown event on that control. It works fine with key like Enter but when I press space bar key it event gets fired.
Do any one have solution for the same.
Thanks, Piyush
hi,
I have written a javascript on a button which blocks the keypress or keydown event on that control. It works fine with key like Enter but when I press space bar key it event gets fired.
Do any one have solution for the same.
Thanks, Piyush
Make sure you're using the correct ascii character code for the keypress event, and make sure you're checking the correct properties for the browser you're testing in. IE uses event.keyCode
, others use event.which
. The following code works fine for me in IE, Firefox and Chrome:
document.getElementById("hello").onkeypress = function (evt)
{
var k = evt ? evt.which : window.event.keyCode;
if (k == 32)
return false;
}