title: Cancel Instant Search when Enter is pressed
body: <h1>The Issue</h1>
  
  <p>There is a timeout function below that ajaxes in the html of the page instantly after an interval of 1200 (jQuery timeout), and it is great until the user presses enter before the timeout is finished, or after, and the html for the page is called twice unnecessarily.</p>
  
  <h2>The Code I am using</h2>
  
  <p><strong>The function called onkeyup of the input</strong></p>
  
  <pre><code> var timeoutReference;
   function instant(){
   var val=some filters;
     if(val!=''){
          if(timeoutReference)clearTimeout(timeoutReference);timeoutReference=setTimeout(function(){
                  ajaxHTML();
          },1200);
     }
    }
  </code></pre>
  
  <p><strong>Same function is called on enter</strong></p>
  
  <pre><code>$(document).on('keypress',function(e){
      if(e.keyCode==13){
          ajaxHTML(); 
      }
  });
  </code></pre>
  
  <h1>Question</h1>
  
  <p><strong>What can I add to stop the Timeout Function if enter is pressed before it, or how can I prevent the same HTML document from being called twice? Thanks</strong></p>