egyedg
egyedg

Reputation: 724

jQuery: How to stop the change() event from firing from the blur() handler?

I have the following scenario:

$("#element").blur(validate).change(onElementChange);

The validate() function should prevent the change event from firing, if the value of the #element is not valid. I cannot add the validate to change, because it needs to validate on blur too. If add the validate() to both events, the alert with the validation error will pop up twice.

So, the my question is, can I stop the change event from firing from the handler of the blur event?

Also if you have a different solution (without using plugins), i would like to hear it.

Thanks

Upvotes: 2

Views: 2172

Answers (2)

egyedg
egyedg

Reputation: 724

I've found a workaround to the problem:

  • handling the validation only after the change event
  • triggering the change event in the handler or the blur (in case)

Upvotes: 1

Josh
Josh

Reputation: 6322

can't you call the onElementChange function inside your validate function when it returns valid.

Upvotes: 0

Related Questions