Click here to Skip to main content
11,712,126 members (56,927 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
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
Edited 6-Feb-13 21:05pm
Ankur\m/50.2K
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 at 7-Feb-13 3:45am
   
No its not working
Member 9378829 at 7-Feb-13 3:47am
   
(i = 0; i < checkBoxList.length; i++) do you think this forloop having a right syntax
manognya kota at 7-Feb-13 3:50am
   
Did you check what are you getting in arrayOfCheckBoxLabels [i].value object?
manognya kota at 7-Feb-13 3:55am
   
Oops...sorry....small correction to be made
its,
arrayOfCheckBoxLabels[i].innerText;
manognya kota at 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
0 CHill60 280
1 Sergey Alexandrovich Kryukov 259
2 OriginalGriff 230
3 Andy Lanng 160
4 Richard MacCutchan 130
0 CHill60 280
1 Sergey Alexandrovich Kryukov 125
2 Andy Lanng 120
3 Abhinav S 95
4 Maciej Los 95


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2015
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