How to ignore a jQuery event when a certain button is clicked?
<p>In my code I have an Ajax lookup bound to the <code>focusout</code> event of a textbox.  The Ajax request will display an error message if the data provided was invalid.  I also have a "cancel" button on a form that, when clicked, hides some fields including the one with the request.  However, if an invalid value is specified in the textbox, clicking the Cancel button fires off the Ajax request (because the textbox loses focus) and the error message gets displayed.</p>

<p>What I want is when I click the cancel button, this Ajax event is <strong>not</strong> fired, so even if the user entered an invalid entry the form will be "closed" without the error message displaying.</p>

<p>Is this possible?</p>

<p>Code is this, basically:</p>

<pre><code>$('#txtPostalCode').focusout(function() { 
    postalCodeLookup($(this).val()); // ajax method wrapper
});

$('button#cancelButton').click(function() { 
    $('#txtPostalCode').attr('disabled', true).addClass('disabled'); // applies CSS style to make textbox look like a label
    $('#txtPostalCode').val($('#oldPostalCode').val()); // restore old value
});
</code></pre>

<p>as I said since the focusout fires before the click, you can't "cancel" the form if there's an invalid entry in the textbox since it will fire the ajax request and come up with the error message.  This issue is from a usability point of view, in that someone might enter an invalid zip code, realize their mistake and then try to cancel the form, but the form won't let itself it be cancelled until they enter a valid zip code (which is then just overridden when the form actually does cancel).</p>

<p>If there's a better way to handle what I want to do I'm all for hearing that as well, this was the first thing that popped into mind when I received the requirement :)</p>
