title: JavaScript check all and uncheck all for checkbox
body: <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  function checkAll(formname, checktoggle)
  {
       var checkboxes = new Array();
        checkboxes = document[formname].getElementsByTagName('input');
        for (var i = 0; i &lt; checkboxes.length; i++) {
            if (checkboxes[i].type === 'checkbox') {
                 checkboxes[i].checked = checktoggle;
            }
        }
  }
  &lt;/script&gt;
  
  &lt;form name=&quot;myform&quot;&gt;
  &lt;li&gt;
     &lt;label class=&quot;cba&quot;&gt;
           &lt;a href=&quot;javascript:void();&quot; onclick=&quot;javascript:checkAll('myform', true);&quot;&gt;Check All&lt;/a&gt; | 
           &lt;a href=&quot;javascript:void();&quot; onclick=&quot;javascript:checkAll('myform', false);&quot;&gt;UnCheck All&lt;/a&gt;
     &lt;/label&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;input class=&quot;cba&quot; type=&quot;checkbox&quot; name=&quot;content1&quot; value=&quot;1&quot;&lt;?php checked('1', $slct); ?&gt;/&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;input class=&quot;cbc&quot; type=&quot;checkbox&quot; name=&quot;content2&quot; value=&quot;2&quot;&lt;?php checked('2', $copy); ?&gt;/&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;input class=&quot;cbx&quot; type=&quot;checkbox&quot; name=&quot;content3&quot; value=&quot;3&quot;&lt;?php checked('3', $cut); ?&gt;/&gt;
  &lt;/li&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I have made the toggle option for the checkbox check all and uncheck all. Still now check all and uncheck all is not working I get the error in console while viewing in Firebug. Here is the screenshot I attached.
  I am not sure what was my mistake:</p>
  <p><img src="https://i.stack.imgur.com/LfaV4.png" alt="enter image description here" /></p>
  <p>Any suggestion would be great.</p>