title: CheckboxList not getting selected values in javascript
body: <p>I have checkbox list in asp.net as:</p>
  
  <pre><code>&lt;asp:CheckBoxList ID="chbUserType" RepeatDirection="Horizontal" runat="server"&gt;
                      &lt;/asp:CheckBoxList&gt;
  </code></pre>
  
  <p>I have binded it as:</p>
  
  <pre><code>chbUserType.DataSource = dtRoles;
          chbUserType.DataValueField = "idRole";
          chbUserType.DataTextField = "Title";
          chbUserType.DataBind();
  
          foreach (ListItem li in chbUserType.Items)
          {
              li.Attributes.Add("JSvalue", li.Value);
          }   
  </code></pre>
  
  <p>I want to get its selected values in javascript.</p>
  
  <p>For that i have done as follows:</p>
  
  <pre><code>    var userType = "";
      var chkBox = document.getElementById('&lt;%=chbUserType.ClientID %&gt;');
  
      var options = chkBox.getElementsByName('input');
      var listOfSpans = chkBox.getElementsByTagName('span');
      for (var i = 0; i &lt; options.length; i++) {
          if (options[i].checked) {
              if (i != options.length - 1) {
                  userType = listOfSpans[i].attributes["JSvalue"].value + ",";
              }
              else {
                  userType = listOfSpans[i].attributes["JSvalue"].value;
              }
          }
      }
  
      alert(userType);
  </code></pre>
  
  <p>I am not getting anything in alert.</p>
  
  <p>Please help me how can i achieve this???</p>
  
  <p><strong>Edit 2 :</strong></p>
  
  <p><strong>Generated HTML</strong></p>
  
  <pre><code>&lt;span jsvalue="2"&gt;&lt;input id="MainContent_chbUserType_1" type="checkbox" name="ctl00$MainContent$chbUserType$1" value="2"&gt;&lt;label for="MainContent_chbUserType_1"&gt;Dispatcher&lt;/label&gt;&lt;/span&gt;
  </code></pre>