0

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?

2
  • It'd help if you posted an example of your code. I don't think blur should be firing from keypress unless your keypress handler is actually causing the element to lose focus. Commented Feb 1, 2009 at 1:32
  • Don't use the keypress event, use the keyup event instead (better supported) Commented Feb 1, 2009 at 1:34

3 Answers 3

2

It sounds like something in your EventHandlerKeyPress() function is raising a blur.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.