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
  • 7,818
  • 9
  • 49
  • 80
matt
  • 40,185
  • 99
  • 257
  • 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
  • 142,114
  • 39
  • 237
  • 299
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,199
  • 1
  • 29
  • 41
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 Wizard Says No More War
  • 64,101
  • 26
  • 136
  • 201
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
  • 21,457
  • 6
  • 48
  • 75