title: validate checkboxlist in ASP.NET client side
body: <p>Im trying to validate my checkbox list with the following code, but for some reason it gives me the errormessage every time, even if the right amount of checkboxes are checked, and I cant find any sulotions anywhere, can anyone spot what Im doing wrong?</p>
  
  <pre><code>&lt;asp:CheckBoxList ID="CheckBoxList" runat="server"&gt;
  &lt;/asp:CheckBoxList&gt;
  
  &lt;asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validate" ErrorMessage="choose a role, not more than 2"
          ValidationGroup="CreateUserWizard1"&gt;&lt;/asp:CustomValidator&gt;
  
      &lt;script type="text/javascript"&gt;
      function validate(source, arguments) {
          arguments.IsValid = false;
  
          var checklist = document.getElementById("CheckBoxList");
          if (checklist == null) return;
  
          var elements = checklist.getElementsByTagName("INPUT");
          if (elements == null) return;
  
          var checkBoxCount = 0;
          for (i = 0; i &lt; elements.length; i++) {
              if (elements[i].checked) checkBoxCount++;
          }
          arguments.IsValid = (checkBoxCount &gt; 0 || checkBoxCount &lt;= 2);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>the script is taken from a similar question on stack, and I can't really figure out what "INPUT" relates to? </p>