title: jQuery handing both focus and click on an element
body: <p>I'm trying to determine workflow to fine-tune a data entry web application.  Picture several address forms on a single web page:</p>
  
  <pre><code>  1. Name___________
       Street_________
       Phone__________
  
    2. Name___________
       Street_________
       Phone__________
  
    [...many more...]
  </code></pre>
  
  <p>Now I'd like to know if the user is using the tab key to get to the second "Name" field (or anywhere within that record), or if they're using the mouse to click on it.  (Or shift-tab to move in reverse.)</p>
  
  <p>I've set a handler on both focus and click for the input fields:</p>
  
  <pre><code>$('input').click(function() { TabulateClick(this) });
  $('input').focus(function() { TabulateFocus(this) });
  </code></pre>
  
  <p>And in the handler, I determine which address the user is working on and whether we've "switched" Address records.  (If the focus was in "Phone" for the first address, and you click on the "Name" field in the <em>same address</em>, that's not actually switching records, so I don't tabulate that.)</p>
  
  <pre><code>    function TabulateClick(field)
      {
           var currentAddressRecord = FindAddress(field);
           if ( lastAddressRecord != currentAddressRecord )
               switchedAddressesWithClick++;
           lastAddressRecord = currentAddress;
      }
      function TabulateFocus(field)
      {
           var currentAddress = FindAddress(field);
           if ( lastAddressRecord != currentAddressRecord )
               switchedAddressesWithTab++;
           lastAddressRecord = currentAddress;
      }
  </code></pre>
  
  <p>My problem is that when I mouse-click into the field the <code>focus</code> event fires first tabulating a false <code>switchedAddressesWithTab</code> and changing the currentAddress (that's <strong>bad</strong>).  When the <code>click</code> handler runs, the <code>lastAddressRecord</code> is spoiled.</p>
  
  <p>Is there a way inside of the <code>focus</code> handler to know that there is a pending <code>click</code> event on the same object?  Or in the <code>click</code> handler to know that it was previously just handled by <code>focus</code>?</p>