title: What is a clean way to check for input changes before issuing an ajax call
body: <p>I've got an ASP.NET MVC 3 project with a form with 5 text input boxes to allow the user to enter search criteria.</p>
  
  <p>Currently, when the user tabs from one field to the next, I've got a <code>$('.watched').blur(ajaxSearch);</code> function that issues my <code>ajaxSearch</code> function and this works ok, sorta...</p>
  
  <p>My issue is that the ajaxSearch gets called each an every time I either tab through the fields, or click on one of the values displayed in the <code>.searchResults</code> result div.</p>
  
  <p>I've put my current search javascript at the end of the question.</p>
  
  <p>I would like to store the values in the textboxes, and then check them for changes before issuing another ajax call.  </p>
  
  <p><strong>Psuedocode idea</strong></p>
  
  <pre><code>var oldvalues =  {}
  function saveCurrentValues() {
      foreach( input box on the form ) {
         save the currentvalue of the input box into oldvalues['inputboxid']
      }
  }
  
  function isNewSearch() {
      foreach( input box on the form ) {
          if (oldvalues['inputbox.id'] !== input box value) {
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>I am unsure how to implement the foreach and the oldvalues assignment.  Could some javascript guru point me in the right direction for this implementation.  (I've put <em>commented</em> lines in the javascript below where I think this implementation should go to actually do the work.)</p>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>function displayResults(data) {
      $('.searchResults').html(data);
  }
  
  function ajaxSearch() {
      // if (isNewSearch() ) {
      //    saveCurrentValues();
            $('#selectedRecord').empty();
            var myForm = $('#searchForm');
            $.post(myForm.URL, myForm.serialize(), displayResults);
      //}
  }
  
  $(function () {
      $('.watched').blur(ajaxSearch);
      //saveCurrentValues();
  });
  </code></pre>