title: jQuery: ajax, submit button that was clicked
body: <p>I have a form with several elements and two submit buttons: SAVE and DELETE. When submitting the form, via jQuery ajax, i need to know if the user clicked on DELETE so i can execute the code accordingly. The problem is that jQuery doesn't send the submit name and value.
  So, i've read here and found what it looks like the ideal workaround: use input for SAVE and a button for DELETE . With a DELETE button i can send the form with the name and value of the button, therefore execute the code for the delete.
  The problem is that im trying to tie the pieces together with no success.
  Here's my code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form id="f-release" method="post" action="includes/submit_release.php"&gt;
      &lt;fieldset&gt;
          &lt;input name="save" type="submit" value="save"&gt;
          &lt;button name="delete" type="button" value="delete" onClick="return confirm('Do you really wish to permanently delete the record?')"&gt;Delete&lt;/button&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>ajax:</p>
  
  <pre><code>$("form button[name=delete]").click(function() {
      var formData = $(this).closest('form').serializeArray();
      formData.push({name: this.name, value:this.value });
  });
  
  $('form#f-release').submit(function(event) {
      event.preventDefault();
  
      var form = $(this);
  
      $.ajax({
          type: form.attr('method'),
          url: form.attr('action'),
          data: form.serialize(),
          dataType: "json"
      }).done(function(data) {
  
          alert('done');  
  
      }).fail(function(data) {
  
          alert('error!');
  
      });
  });
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>if (isset($_POST['releaseid']) &amp;&amp; is_numeric($_POST['releaseid'])) {
  
      // save
  
  } elseif (...delete...) {
  
      //delete
  
  }
  </code></pre>
  
  <p>When i click delete, how do i submit the form with the name and value of the delete button so i can execute the php DELETE code correctly?</p>