title: Auto deselect onclick checkbox using JS
body: <p>First thing's first. I can't use JQuery, only JS.</p>
  <p>I have some checkboxes all with different names. I need the different names. I then have another checkbox that when clicked should deselect the previous checkboxes.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var isAllCheck = false;
  
  function togglecheckboxes(cn) {
  
    var cbarray = document.getElementsByName(cn);
    for (var i = 0; i &lt; cbarray.length; i++) {
  
      cbarray[i].checked = !isAllCheck
    }
    isAllCheck = !isAllCheck;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="checkbox" name="email"&gt;
  &lt;input type="checkbox" name="phone"&gt;
  &lt;input type="checkbox" name="sms"&gt;
  &lt;input type="checkbox" name="whatsapp"&gt;
  &lt;input type="checkbox" onclick="togglecheckboxes('cb')" value="Toggle all"&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>if the names are all 'cb' then it works but I need them to be different. Is there anyway i can get this to work while maintaining different names?</p>
  <p>huge thanks in advance.</p>