Reputation: 3973
I have an input box, and I have bound both blur
and keypress
events to the input, but the problem is when there is a keypress
event, blur
event also fires. Is there any way to suppress the blur
event when keypress
event occurs?
Upvotes: 0
Views: 1781
Reputation: 336
I simplified your code a little just to test and couldn't come to the same conclusion about the order of events firing. Firebug's console shows the following code execution yielding .keypress always occuring before a .blur
<script>
$(document).ready(function() {
$("#inpt").blur(function(e) {
console.log(".blur");
});
$("#inpt").keypress(function(e) {
console.log(".keypress");
});
});
</script>
What exactly are you trying to accomplish with .onchange, and .keypress bound to the same field? Might help if you posted your event handler code as well.
Also, you have a global document.keypress bound as well, any particular reason for that?
Upvotes: 1
Reputation: 60580
It sounds like something in your EventHandlerKeyPress() function is raising a blur.
Upvotes: 2
Reputation: 3973
<script src="jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#inpt").blur(function(e) {
EventHandlerBlur(e);
});
$("#inpt").keypress(function(e) {
EventHandlerKeyPress(e);
});
$(document).keypress(function(e) {
EventHandlerKeyPress(e);
});
});
</script>
here is the code with same behavior. actually on entering on input/ or even pressing any key on input box is causing blur event to fire first before the keypress event..
Upvotes: 0