title: Form submitted twice using submit() on keyup
body: <p>I had a jQuery / HTML code similar to this:</p>
  <pre><code>&lt;form action=&quot;/SomeAction&quot; method=&quot;post&quot;&gt;
    &lt;input id=&quot;my-textbox&quot; type=&quot;text&quot; placeholder=&quot;Write something and press enter to continue...&quot; /&gt;
  &lt;/form&gt;
  
  &lt;script type=&quot;text/javascript&quot;&gt;
   $(function() {
       $('#my-textbox').keyup(function(e) {
          var $textbox = $(this);
          if ($textbox.val().length &gt; 0 &amp;&amp; e.keyCode == 13) {
             $textbox.parent('form').submit();
          }
       });
   });
  &lt;/script&gt;
  </code></pre>
  <p>The purpose was to automatically submit the form when the user pressed the <kbd>Enter</kbd> key. I regularly use Firefox so everything was OK for me until I tested in Google Chrome and Internet Explorer.</p>
  <p>When I pressed the <kbd>Enter</kbd> key in the later browsers, sometimes I would get the form submitted twice. This was easy to notice because I would get duplicate entries in my DB and I'd see two <code>POST</code>s using Fiddler.</p>
  <p>After some testing, I found out that my problem was the jQuery code, since the textbox would submit automatically on enter without it, and using this code would produce a second <code>POST</code> in some browsers.</p>
  <p><strong>My questions are:</strong></p>
  <p>Why don't browsers smartly prevent the second form post (like Firefox did in my testing)?</p>
  <p>Should I expect this behavior in all major browsers in all platforms?</p>
  <p>Is there a way to improve this code so I perform the submit using JavaScript, but don't get the form submitted twice?</p>