I'm having a textbox and assigned the following function (it's the only function assigned):
txt.bind("keyup",function(event){
if(event.keyCode==13)
{
var nu = $("#debug").html();
nu+="<br>enter";
$("#debug").html(nu);
}
});
The strange thing is that it's actually firing twice, thus displaying "enter" twice in my debug window. Does anyone know what is causing this?
I'm embarrassed to even mention this, but I was typing a capital letter into my textbox and so the release of my shift key was causing the supposed "second firing" of the keyup event. Turns out it wasn't a second firing at all, but it just fooled me into thinking it was for while. At first I thought the unbind trick mentioned above simply wasn't working for me, but it was. I hope this helps others like me that might have done the same thing. Now I simply make sure I always check that its not just the shift key being released in the handling of my event and all is well again.
I know it's been quite awhile, but I'm surprised nobody suggested:
txt.unbind();
txt.bind("keyup",function(event){
if(event.keyCode==13)
{
var nu = $("#debug").html();
nu+="<br>enter";
$("#debug").html(nu);
}
});
If somehow txt
got bound already, calling unbind before your new bind should fix it. Of course it's preferable to figure out why it's being bound twice. This just happened to me, because I accidentally had my JavaScript file included twice. Calling unbind helped me determine that was the problem.
i found out by myself - txt.bind was assigned twice to the textbox so it fired twice. is this a bug? i thought binding a function will always fire just once .. hmm
I'm having the same issue - keyup and keydown events are being fired twice though their handlers are bound only once and I'm definitely attaching them to only one element.
The interesting point is that this behavior can be observed only in Internet Explorer and in just one special case where my webapp is displayed in an embedded ActiveX control (CLSID_InternetExplorer). OS: Windows 7, IE 8, embedded ActiveX control is running in IE7 compatibility mode.
I've found a workaround however - process the jQuery's keypress event, which made also more semantic sense in my webapp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With