title: How can I prevent a later binding on a jQuery autocompleter from firing?
body: <p>The below code is very simple. I have a jQuery <a href="http://docs.jquery.com/Plugins/Autocomplete" rel="nofollow noreferrer">autocomplete</a> bound to an html text input referenced by <code>#search</code>. When the user types something into it, a drop-out list shows suggestions from the server. If the user clicks on one of the suggestions, or presses Enter with it selected, a popup (facebox) appears showing the called page within the popup. If instead the user just wants to execute a normal search and not select a suggestion, he can do so by pressing Enter or clicking <code>#searchButton</code>. In other words:</p>
  
  <ol>
  <li>User types something in, e.g.
  grapefruit</li>
  <li>Selectable suggestions appear.</li>
  <li>Scenario 1: User selects a
  suggestion with mouse or keyboard,
  presses enter, or clicks it - causing that
  item to pop up, i.e. autocomplete's
  result .handler fires (and not
  .keypress)</li>
  <li>Scenario 2: User is not interested
  in the suggestions, and instead presses
  enter OR clicks on <code>#searchButton</code> to execute a full search on what he's typed into <code>#search</code>. Autocomplete's result handler does not fire, instead, either the Enter keypress triggers <code>#searchButton</code>'s click event, or it is triggered directly (ie, actually clicked) thereby triggering a normal search.</li>
  </ol>
  
  <p>This works beautifully in IE6, IE7, IE8, Chrome, Safari, but NOT in firefox.</p>
  
  <p>In firefox, when Enter is pressed on a suggestion, both the result handler and the keypress events fire, giving the user the facebox popup, as well as executing the full search. I figured that somehow stopping <code>.keypress</code> from firing if .<code>result</code> fires would do the trick, however, I have not been able to figure out how to do so. I tried putting using jQuery's <code>stopPropogation()</code> and <code>stopImmediatePropogation()</code> into the .result handler in the hope that it would prevent .keypress from firing, but it didn't change a thing.</p>
  
  <p>If anyone has any thoughts, or would like to help me through this, I would be most appreciative.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>    jQuery("#search").autocomplete("/index/suggest", {
          selectFirst: false,
          formatItem: function(data, i, n, value) {
              return "&lt;font color='#3399CC'&gt;" + value.split("::")[0] + "&lt;/font&gt;";
          },
          formatResult: function(data,value) {
              return value.split("::")[0];
          }
      }).result(function(event, data, formatted) {
          alert('Hello, someone selected a suggestion by clicking on it or pressing enter on it, so you\'re getting this!');
          var pieces = formatted.split("::");
          var url = '/' + pieces[1] + '/detail/?id=' + pieces[2];
          jQuery.facebox({ ajax: url });
      }).keypress(keypressHandler).blur(function() {
          alert('I don\'t want this to appear if .result above is called, and it doesnt, except in firefox! Bah!');
          jQuery(this).flushCache();
      });
  
      function keypressHandler(e)
      {
          if(e.which == 13) {
              if(!jQuery('#searchButton').is(':disabled')) {
                  jQuery(this).blur();
                  jQuery('#searchButton').focus().click();
              }
          }
      }
  </code></pre>