title: Handle user hitting 'Enter' key in a ASP.NET MVC web site
body: <p>I am working on a ASP.NET MVC web site that has multiple submit buttons. i.e.</p>
  
  <pre><code>    &lt;input type="submit" name="SubmitButton" value="Reset" /&gt;
      &lt;input type="submit" name="SubmitButton" value="OK" /&gt;
      &lt;input type="submit" name="SubmitButton" value="Back" /&gt;
  </code></pre>
  
  <p>I need to allow users to quickly submitting the form by pressing the 'Enter' key. HTML standard seems to specify that the first submit button will be assumed if a user press the 'Enter' key. However, I need to make the 2nd button (i.e. the "OK") button the default button and for reasons I don't even want to talk about, changing the button order is not an option. </p>
  
  <p>I googled around and I found <a href="http://marekblotny.blogspot.com/2009/03/defaultbutton-deal-with-users-hitting.html" rel="noreferrer">this post</a> about using Page.Form.DefaultButton in ASP.NET but this doesn't work with ASP.NET MVC.</p>
  
  <p>I also tried the following javascript solution, while it works in Chrome but doesn't work in IE6</p>
  
  <pre><code>    $('body').keypress(function(e) {
         if (e.which === 13) {
            $("input[value='OK']").trigger('click');
         }
      });
  </code></pre>
  
  <p>I can think of some really extreme solutions such as going through every single controls in the form an attach the above function to them. However, I don't think that's a very neat solution so I am wondering has anyone got a better solution?</p>