title: How to detect "tab keypress" when focus is at a button using JavaScript
body: <p>I'm just wondering if any of you done an onkeypress on a button.</p>
  
  <p><strong>my button is like this:</strong></p>
  
  <pre><code>asp:Button ID="btnClear" runat="server" Text="Clear" onkeypress="return goToFirst();"/&gt;
  </code></pre>
  
  <p><strong>the javascript:</strong></p>
  
  <pre><code>function goToFirst(evt) {
      var e = event || evt; // for trans-browser compatibility
      var charCode = e.which || e.keyCode;
  
      alert(charCode);
      if (charCode = 9 ) {
          document.getElementById('txtFirstName').focus();
          document.getElementById('txtFirstName').select();
      }
  
      return false;
  </code></pre>
  
  <p>My goal is to detect the tab keypress on a button and set the focus on the specified textbox when tab is pressed. </p>
  
  <p>The problem is that the onkeypress event does not fire when tab key is pressed. other keys like numbers and letters fires the event, but not tab. </p>
  
  <p>Is there a solution to my goal?</p>
  
  <p>Thanks in advance!</p>