Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code:
JavaScript
<script type="text/javascript" language="javascript">
             function GetTextValue() {
  var checkList = document.getElementById('CheckBoxList1');
                     var checkBoxList = checkList.getElementsByTagName("input");
                     var checkBoxSelectedItems = new Array();
                     var values = "";
                     var i = 0;
                     for (i = 0; i < checkBoxList.length; i++) {
                         if (checkBoxList[i].checked) {
                             checkBoxSelectedItems.push(checkBoxList[i].value);
                             values = values + checkBoxList[i].value + ",";
                             alert('checked - checkBoxList[i]: ' + checkBoxList[i].value)
                         }
                     }
                     var category = values;
}
</script>


For example if i select three check box then it shows like this "on, on, on"
Posted
Updated 6-Feb-13 21:05pm
v2

1 solution

Hi,

can you try this?

XML
<script type="text/javascript" language="javascript">
             function GetTextValue() {
  var checkList = document.getElementById('CheckBoxList1');
                     var checkBoxList = checkList.getElementsByTagName("input");
var arrayOfCheckBoxLabels = checkBoxList.getElementsByTagName("label");

                     var checkBoxSelectedItems = new Array();
                     var values = "";
                     var i = 0;
                     for (i = 0; i &lt; checkBoxList.length; i++) {
                         if (checkBoxList[i].checked) {
                             checkBoxSelectedItems.push(checkBoxList[i].value);
                             values = values + arrayOfCheckBoxLabels[i].innerText + ",";
                           
                         }
                     }
                     var category = values;
}
 
Share this answer
 
v3
Comments
Member 9378829 7-Feb-13 3:45am    
No its not working
Member 9378829 7-Feb-13 3:47am    
(i = 0; i < checkBoxList.length; i++) do you think this forloop having a right syntax
manognya kota 7-Feb-13 3:50am    
Did you check what are you getting in arrayOfCheckBoxLabels [i].value object?
manognya kota 7-Feb-13 3:55am    
Oops...sorry....small correction to be made
its,
arrayOfCheckBoxLabels[i].innerText;
manognya kota 7-Feb-13 4:00am    
For a clear explanation for the above, you can refer the below link
http://www.dotnetboss.com/2010/05/25/how-to-get-the-checkboxlist-value-using-javascript/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900