title: How to insert and update checkbox value correctly into database?
body: <p>I'm working on a JSP application and I have a form which has a checkbox, what I try to do is to insert and update into my DB "0 or 1" depending if it's checked or unchecked. What my code does already is to insert "1" always insert "1" instead of "0" if it's unchecked and when I try to update my DB, example from "1" to "0" or form "0" to "1", It does not do the work, my checkbox does not toggle. Please help me!</p>
  
  <p>I already have my method to insert and update and it works, because I can insert or update the additional fields of the form.</p>
  
  <p>JSP code: </p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;Principal:&lt;/td&gt;
  &lt;td colspan="2"&gt;&lt;input type="checkbox" id="a_principal" name="a_principal" value="&lt;%=directorio!=null?(directorio.isPrincipal()!=false?directorio.isPrincipal(): ""):""%&gt;" /&gt;
  &lt;%=directorio.isPrincipal()%&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>Javascript code:</p>
  
  <pre><code>$(function (){  
      if($('#a_principal').val()== "true"){           
           $("input:checkbox").prop('checked',true);        
      }else{
          $("input:checkbox").prop('checked', false);        
      }
  });
  </code></pre>
  
  <p>Thanks in advance!!</p>