title: Simplest way to disable button on submission of a form?
body: <p>I've been trying to find the "right" way to prevent double submits of forms.  There are lots of related posts on SO but none of them hit the spot for me.  Two questions below.</p>
  
  <p>Here is my form</p>
  
  <pre><code>&lt;form method="POST"&gt;
      &lt;input type="text" name="q"/&gt;
      &lt;button class="once-only"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my first attempt to disable double submits:</p>
  
  <pre><code>$(document).ready(function(){
      $(".once-only").click(function(){
          this.disabled = true;
          return true;
      });
  });
  </code></pre>
  
  <p>This is the approach suggested here: <a href="https://stackoverflow.com/questions/4852847/disable-button-after-post-using-js-jquery">Disable button after post using JS/Jquery</a>. That post suggests the submitting element must be an input rather than a button, but testing both makes no difference.  You can try it yourself using this fiddle: <a href="http://jsfiddle.net/uT3hP/" rel="noreferrer">http://jsfiddle.net/uT3hP/</a></p>
  
  <p>As you can see, this disables the button, but also prevents submission of the form.  In cases where the submitting element is a button and an input element.</p>
  
  <p><strong>Question 1:</strong> why does this click handler stop submission of the form? </p>
  
  <p>Searching around some more I find this solution (from <a href="https://stackoverflow.com/questions/400616/why-doesnt-my-form-post-when-i-disable-the-submit-button-to-prevent-double-clic">Why doesn&#39;t my form post when I disable the submit button to prevent double clicking?</a>)</p>
  
  <pre><code>if($.data(this, 'clicked')){
      return false;
  } else{
      $.data(this, 'clicked', true);
      return true;
  }
  </code></pre>
  
  <p>You can play with this using this fiddle: <a href="http://jsfiddle.net/uT3hP/1/" rel="noreferrer">http://jsfiddle.net/uT3hP/1/</a></p>
  
  <p>This does work, but...</p>
  
  <p><strong>Question 2:</strong>  Is this the best we can do?</p>
  
  <p>I thought this would be an elementary thing.  Approach 1 does not work, approach 2 does, but I don't like it and sense there must be a simpler way.</p>