Skip to content Skip to sidebar Skip to footer

Event.which And Event.keycode Is Not Working On Internet Explorer 10 For Backspace Button

I have to track the alphabet keys and backspace key with JavaScript. I am using below written code to track every key press but unfortunately when i press backspace button in IE i

Solution 1:

If you want to support IE and you use special keys (like delete and backspace) I suggest using keydown/keyup instead.

Special keys

Explorer doesn't fire the keypress event for delete, end, enter, escape, function keys, home, insert, pageUp/Down and tab.

If you need to detect these keys, do yourself a favour and search for their keyCode onkeydown/up, and ignore both onkeypress and charCode.

You can read more on cross browser issues of Detecting keystrokes(Quirksmode).

OR

Key Code for Backspace will take the value = 83if we already have a few characters in a Text Box .

The Key Code will be = 8if there are NO Characters in the Text Box and we are trying to Hit Backspace.

Solution 2:

If you want to support IE and you use special keys (like delete and backspace) I suggest using keydown/keyup instead.

Solution 3:

The problem araises when you are using IE10 . Because in the IE versions < 9 give

event.which == undefined || event.which == zero 

when special handling key is pressed like Backspace,DEL,INS,HOME,Navigation Keys, Enter, etc. So we could easily identify when a special handling character is pressed and can be handled seperately.

But in IE10 . event.which doesn't give undefined or zero for special handling keys instead it gives keycode.... Surprising thing is , It gives same key code for Dot( . ) and Delete , Single quote( ' ) and Right arrow , etc.

Hence we couldn't identify exactly in IE10 when special handling key is pressed by using neither event.which nor event.keycode .

In such Situations ... Use

event.charCode == 0

For identifying special handling characters in IE10

Trust me friends, It saved me more than a week's effort.

Post a Comment for "Event.which And Event.keycode Is Not Working On Internet Explorer 10 For Backspace Button"