Lakshmi
Lakshmi

Reputation: 175

In IE9, for keyup event When I use the enter key "event" is not getting, for other keys Iam getting keycode values

When I use Enter key, alert("kcode=="+e.which) the kcode is getting undefined and the if condition is not executed in IE9.

In HTML

<input type="text" id="test"/>

In JS

$(document).ready(function(){
    $("#test").keyup(function(e){

        var kcode = e.which || e.keyCode;
       alert("kcode=="+e.which);
        if (kcode == 13){
            alert("in if");
        }

    });
})

Upvotes: 1

Views: 701

Answers (2)

serguitus
serguitus

Reputation: 526

It seems that IE has some special keys for which it doesn't trigger 'keyup' when pressed. I found this behavior on IE11 for 'keyup'. Instead, I used 'keypress' and worked fine. I also found other internet posts refering similar situations with IE and other key events. this is one of them Hope this helps someone to survive IE issues :)

Upvotes: 1

gkempkens
gkempkens

Reputation: 460

Probably you need to use window.event in IE. You can try this fiddle I've setup:

http://jsfiddle.net/ytphedvg/

I've tested it in IE9, it works perfectly.

JS

$(document).ready(function(){
    $("#test").keyup(function(e){
        var ev = e || window.event;
        var kcode = ev.which || ev.keyCode;
        alert("kcode=="+ev.which);
        if (kcode == 13){
            alert("in if");
        }
    });
});

Upvotes: 0

Related Questions