title: Uncheck CheckBoxes with Javascript Not working
body: <p>First thing, I searched SO and there are many questions with same title but none of them has the answer and I tried all of these answers with many different versions of my own but nothing works.</p>
  
  <p>So, I have a form with many checkboxes and I want to uncheck all checkboxes when user change the user from <strong>userSelection</strong> list. like this</p>
  
  <pre><code>&lt;form id="myForm"&gt;
      &lt;select id="userSelection" onchange="userChange()"&gt;
          &lt;option value="0" acl=""&gt;Select User&lt;/option&gt;
          &lt;option value="1" acl="2,5"&gt;ABC&lt;/option&gt;
          &lt;option value="2" acl="3,4"&gt;DEF&lt;/option&gt;
      &lt;/select&gt; 
  
      &lt;label&gt;&lt;input type="checkbox" ac="2" name="chkAc"&gt;&lt;p&gt;Income / Expense&lt;/p&gt;&lt;/label&gt;
      &lt;label&gt;&lt;input type="checkbox" ac="3" name="chkAc"&gt;&lt;p&gt;Donations&lt;/p&gt;&lt;/label&gt;
      &lt;label&gt;&lt;input type="checkbox" ac="4" name="chkAc"&gt;&lt;p&gt;Annual Fees&lt;/p&gt;&lt;/label&gt;
      &lt;label&gt;&lt;input type="checkbox" ac="5" name="chkAc"&gt;&lt;p&gt;Members Password&lt;/p&gt;&lt;/label&gt;
  &lt;/form&gt;
  
  &lt;script type="text/javascript"&gt;
    function checkUncheckFields(isAllCheck)
    {
       var cbarray = document.getElementsByName('chkAc');
       for(var i = 0; i &lt; cbarray.length; i++)
       {
            isAllCheck == false? cbarray[i].checked=false : cbarray[i].checked = true;
       }
    }
  
    function userChange()
    {
       checkUncheckFields(false);
       var access = $("#userSelection option:selected").attr('acl').split(',');
       $('input[type=checkbox]').each(function()
       {
          if(access.indexOf($(this).attr('ac')) &gt; -1)
          {
              $(this).attr('checked',true);
          }
       });
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now when I go to my page, manually check all of these checkboxes and then change my user from userSelection list, it does not uncheck checkboxes and if does uncheck all checkboxes then It doesnot check checkboxes meeting condition in user change. I am using JQuery 1.11.0</p>
  
  <p>I have made JSBin here Please check it <a href="http://jsbin.com/famehaguni/1/watch" rel="nofollow">http://jsbin.com/famehaguni/1/watch</a>  plese first check all checkboxes and then change user. Then you can see in our userChange() function we have given the condition to check checkboxes with user's acl attibute values but it doesnot check them means when you select ABC user then it should check 2 and 5 Checkboxes and if you choose DEF user then it should check 3 and 4 checkboxes</p>