Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  65] [ 3]  / answers: 1 / hits: 46114  / 14 Years ago, wed, november 3, 2010, 12:00:00

I'm trying to catch the pressing event of Backspace and Delete keys using javascript/jQuery with this kind of code.



$(textarea[name=txt]).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;

if(keycode == 8){ // backspace
// do somethiing
alert(keycode);
}

if(keycode == 46){ // delete
// do somethiing
alert(keycode);
}

});


These lines of code works perfectly in Firefox (3.6.12). That means the alert is popped up when Backspace or Delete is pressed.
But this is not working in Internet Explorer (8)



Can anyone suggest me a different way to catch these key press events in Internet Explorer?


More From » jquery

 Answers
12

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).


[#95097] Sunday, October 31, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;