Click here to Skip to main content
12,950,399 members (64,814 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
My Code:
<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 6-Feb-13 20:55pm
Updated 6-Feb-13 21:05pm
Ankur\m/50.5K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

can you try this?

<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;
}
 
  Permalink  
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100