title: Select all checkbox to be checked if all checkboxes are checked
body: <p>I need my <code>selectAll</code> checkbox to be checked if all the other checkboxes are checked.
  Any idea how to do this in javascript?</p>
  
  <p>My javascript code:</p>
  
  <pre><code>function selectAll(box) {
      var selectAllchk = box.checked;
      var checkboxes = document.getElementsByName('chkbox');
      if (box.checked){
          for (var i in checkboxes){
              $(":checkbox").attr("checked", true);
          }
      } else {
          $('input:checkbox:not(:disabled)').removeAttr('checked');
      }
  }
  
  
  function selectCheckAll(box){
      var a = ('.checkbox').length;
      if ($(':checkbox:checked').length == $('.checkbox').length) {
         //do something
      }
  };
  </code></pre>
  
  <p>Jsp code:</p>
  
  <pre><code>&lt;td align="center" colspan="5"&gt;
    &lt;display:table name="contratBonusForm" property="contrats" defaultsort="1" 
    sort="list" defaultorder="ascending" requestURI="/gestionContratBonusActionIn.do?dispatch=searchContrat" 
    uid="current" pagesize="30" class="tableauDisplayTag"&gt;
     &lt;display:column title="ID Type" property="id" sortable="true"/&gt;
     &lt;display:column title="Type de contrat" property="type" sortable="true"/&gt;
    &lt;% %&gt;
    &lt;display:column title="Bonus &lt;input type='checkbox' name='selectall' onClick='selectAll(this)'/&gt;" align="center" &gt;
    &lt;% TypeContratPOJO type = (TypeContratPOJO) pageContext.getAttribute("current");
    Long Eli = 1L;
    int ok = type.getBonus().compareTo(Eli);
    (current != null &amp;&amp;  ok == 0) { %&gt;
    &lt;input type="checkbox" name="chkbox" checked="checked" onClick='selectCheckAll(this)' value="&lt;%=indice%&gt;"/&gt;
    &lt;% } else { %&gt;
    &lt;input type="checkbox" name="chkbox" value="&lt;%=indice%&gt;"/&gt;
    &lt;% } %&gt;
    &lt;/display:column&gt;
    &lt;%indice++; %&gt;            
    &lt;/display:table&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>When I select a checkbox it does not enter the selectCheckAll function.</p>