title: How to auto submit a checkbox
body: <p>Here is HTML/JavaScript:</p>
  
  <pre><code>&lt;form method = "post" style="display: inline;" name="thisform&lt;?php echo $employee-&gt;id; ?&gt;"&gt;
                       &lt;input type="hidden" name="user" value="&lt;?php echo $employee-&gt;id; ?&gt;" /&gt;
                       &lt;input type="hidden" name="auto" value="&lt;?php echo $employee-&gt;stay_live; ?&gt;" /&gt;
                      &lt;h3&gt;&lt;input type="checkbox" name="stay_live"  onclick="document.forms.thisform&lt;?php echo $employee-&gt;id; ?&gt;.submit();" &lt;?php if ($employee-&gt;stay_live == '1') { echo "checked"; } ?&gt; title="Click to Stay Live Every Day" /&gt;&amp;nbsp;&lt;?php echo $employee-&gt;name; ?&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is <code>PHP</code>:</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['stay_live'])) {
          $user=$_POST['user'];
          $auto=$_POST['auto'];
  
  
          if ($auto == 1) {
              $sql = "UPDATE users SET stay_live = 0 WHERE id = '{$user}';"; 
          }
  
          if ($auto != 1) {
              $sql = "UPDATE users SET stay_live = 1 WHERE id = '{$user}';";
          }
  
          mysqli_query($dbconnection, $sql);
      }
  ?&gt;
  </code></pre>
  
  <p>If you see the <code>onclick</code> code in the form, it will auto-submit form and do PHP <code>POST</code>.  However, the <code>onclick</code> only works if the <code>checkbox</code> is NOT checked.  If it IS checked, the screen does refresh, as if it did thing, but the POST is never submitted.</p>
  
  <p>So to summarize; everything works as expected when the box is not checked and it needs to be set.  But to UNSET it, the server function is never called.  Can anyone see why?</p>
  
  <p>note:  this is test code, so please no comments on sql injection</p>