title: Is there a way to know if an HTML form is currently submitting?
body: <p>I have a race condition in which I do not want an AJAX call to occur, if a form on the page is currently submitting.</p>
  
  <p>I'd rather not alter the code for the form.</p>
  
  <p>I was thinking of attaching event handlers to each of the form elements so that onsubmit it would increment a counter and then on onreadystatechange decrement the counter.</p>
  
  <p>Then before the AJAX call, check to ensure the counter is zero before firing.</p>
  
  <p>However is there an easier way such as (pseudo code):</p>
  
  <pre><code>form.isSubmitting 
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>The race condition is not because of the JavaScript per-say. It is caused by what happens on the server side on response of the ordering of these actions.</p>
  
  <p>To give you an idea of the broader problem:</p>
  
  <p>A cookie is set when the form post returns.
  On the AJAX call (needs to happen every X seconds)... the server-side (if the form post has happened) expects the cookie to be set.</p>
  
  <p>Sometimes.... </p>
  
  <p>If there is a delay in the form submission returning (and setting the cookie client side), the AJAX call is triggered without sending the cookie back.</p>
  
  <p>The server expects the cookie, because as far as it is concerned the form post has been successful.</p>
  
  <p>However it is the client side I need to control to ensure the actions are performed in a prescribed way.</p>
  
  <p>So correct JavaScript itself cannot cause race conditions, but (as far as my testing has shown) - the submission and returning of POST/AJAX calls causes a race condition in my particular case.</p>