title: Access 'post' data using JavaScript or check which submit button was used to submit the form
body: <p>Consider a simple form with 2 submit buttons</p>
  
  <pre><code>&lt;form method="post"&gt;
   &lt;button type="submit" name="command" value="cancel"&gt;Cancel Order&lt;/button&gt;
   &lt;button type="submit" name="command" value="proceed"&gt;Save Order&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Once submitted, the server will know which submit button was used to submit the form by checking the value for <code>command</code>. Great!</p>
  
  <p>In this case, I am using the <code>onsubmit</code> event handler of the form to preprocess and send the form data via AJAX. Like this: <code>&lt;form method="post" onsubmit="return ajaxSubmit(this);"&gt;</code></p>
  
  <p>I'm using this <code>ajaxSubmit</code> function as a general way to check through any supplied form's elements and send the data via Ajax instead. This works fine for determining the value of text fields, if checkboxes are "checked", which radio is selected in a group, etc. The only thing it seems to get wrong (because I'm not sure how to check this) is which submit button was used to submit the form. i.e There is nothing in <code>myForm["command"]</code> to tell which of the 2 command buttons was actually used.</p>
  
  <p>Instead, is there a way to access the same 'post' data that the server receives with JavaScript before it is sent?</p>
  
  <p>Otherwise, is this just a flaw I need to work around? What's the best way?</p>
  
  <p><strong>Edit:</strong>
  Since all modern browsers will pass the name/value of the button used to submit the form (along with the other relevant parts like which option is selected from a group, checked checkbox name/values, etc.) can anyone explain why there is no way to access this data directly before it is sent to the server? Is there a reason why we shouldn't be able to?</p>