title: javascript: Unchecking all checkboxes
body: <p>I have problem dealing with unchecking all checkboxes. When I click on a toggle all checkbox, it could check all checkboxes. But if I uncheck the toggle all checkbox, nothing happens. All checkboxes are not unchecked. Below is my coding in javascript:    </p>
  
  <pre><code>&lt;script&gt;
  var isAllCheck = false;
  function togglecheckboxes(cn){
  
      var cbarray = document.getElementsByName(cn);
      for(var i = 0; i &lt; cbarray.length; i++){
  
          if( isAllCheck == false ){
              cbarray[i].checked = "true";
              //alert( "it is false" );
          }else{ 
              cbarray[i].removeAttribute("checked");
              //alert( "it is true" );
          }
  }   
  isAllCheck = !isAllCheck;   
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I had even tried this coding, but still failed:</p>
  
  <pre><code>&lt;script&gt;
  var isAllCheck = false;
  function togglecheckboxes(cn){
  
      var cbarray = document.getElementsByName(cn);
      for(var i = 0; i &lt; cbarray.length; i++){
  
          if( isAllCheck == false ){
              cbarray[i].checked = "true";
              //alert( "it is false" );
          }else{ 
              cbarray[i].checked = "false";
              //alert( "it is true" );
          }
  }   
  isAllCheck = !isAllCheck;   
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Below is my PHP coding for your reference:</p>
  
  <pre><code>echo "\t&lt;div class='item'&gt;
  &lt;span class='CDTitle'&gt;{$cd['CDTitle']}&lt;/span&gt;
  &lt;span class='CDYear'&gt;{$cd['CDYear']}&lt;/span&gt;
  &lt;span class='catDesc'&gt;{$cd['catDesc']}&lt;/span&gt;
  &lt;span class='CDPrice'&gt;{$cd['CDPrice']}&lt;/span&gt;
  &lt;span class='chosen'&gt;&lt;input type='checkbox' name='cd[]' value='{$cd['CDID']}' title='{$cd['CDPrice']}' /&gt;&lt;/span&gt;
  &lt;/div&gt;\n";
  </code></pre>
  
  <p>Any tips on resolving this problem. Thanks in advance!</p>