title: Submit form on select change via AJAX
body: <p>Let's say I have this form :</p>
  
  <pre><code>&lt;form action="Change-status.php" method="post"&gt;
          &lt;select class="changeStatus" name="changeStatus"&gt;
                  &lt;option value="0"&gt;Starting&lt;/option&gt;
                  &lt;option value="1"&gt;Ongoing&lt;/option&gt;
                  &lt;option value="2"&gt;Over&lt;/option&gt;
          &lt;/select&gt;
          &lt;input class="projectId" type="hidden" name="projectId" value="&lt;?php echo $data['id'];?&gt;"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I am currently using this script to submit the form, but it implies refreshing :</p>
  
  <pre><code>$('select').change(function ()
  {
      $(this).closest('form').submit();
  });
  </code></pre>
  
  <p>What I want to do is to send the form on select change <strong>without refreshing the page</strong>. I know I have to use AJAX to do so but I couldn't exactly figure out how to implement it.</p>
  
  <p>Could you orient me on how to do this?</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>After taking comments into consideration, I ended up with the following code :</p>
  
  <p>Html :</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
          &lt;select class="changeStatus" name="changeStatus"&gt;
                  &lt;option value="0"&gt;Starting&lt;/option&gt;
                  &lt;option value="1"&gt;Ongoing&lt;/option&gt;
                  &lt;option value="2"&gt;Over&lt;/option&gt;
          &lt;/select&gt;
          &lt;input class="projectId" type="hidden" name="projectId" value="&lt;?php echo $data['id'];?&gt;"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>JS :</p>
  
  <pre><code>$(document).ready(function() {
      $('select.changeStatus').change(function(){
          $.ajax({
                  type: 'POST',
                  url: 'Change-status.php',
                  data: {selectFieldValue: $('select.changeStatus').val(), projectId: $('input[name$="projectId"]').val()},
                  dataType: 'html'
           });
      });
  });
  </code></pre>
  
  <p>PHP :</p>
  
  <pre><code>&lt;?php
      include('../Include/Connect.php');
  
      $changeStatus=$_POST['selectFieldValue'];
      $id=$_POST['projectId'];
  
      $sql='UPDATE project SET progress="'.$changeStatus.'" WHERE id="'.$id.'"';
  
      mysql_query($sql) or die("Erreur: ".mysql_error());
  ?&gt;
  </code></pre>