0

I have a textarea with a blur function:

$("#comment").blur(function() {
        ...something
    });

I don't want this blur() to happen when I click on the submit button below. How can I solve this?

Anders
  • 8,307
  • 9
  • 56
  • 88
matt
  • 42,713
  • 103
  • 264
  • 397

4 Answers4

0

a normal submit is a PAGE REFRESH

So: when your page loads again, the blur() code will get called as well

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

In your submit pass a variable back to the server in the form that indicates that it was a form submit (ie a meaningful flag). When you re-render the page render it with the flag, stating it was a form submit, in javascript. Look for that flag in your blur handler, clear it, and return false.

scrappedcola
  • 10,423
  • 1
  • 32
  • 43
0

Something like this should work:

var _commentBlurTimer = 0;
$("#comment").blur(function() {
   _commentBlurTimer = window.setTimeout(function() {
      //...something
   }, 500);
});

$("input[type=submit]").click(function() {
   if (_commentBlurTimer)
      window.clearTimeout(_commentBlurTimer);
});

Test case: http://jsfiddle.net/yahavbr/a9xZW/

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

Have you tried taking a look at When onblur occurs, how can I find out which element focus went *to*? -- it should help in this case so you can determine whether to fire the 'blur' function or not based on where the focus went to

Community
  • 1
  • 1
Gary Green
  • 22,045
  • 6
  • 49
  • 75