Click here to Skip to main content
11,411,494 members (67,097 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 21:55pm
Edited 6-Feb-13 22:05pm
Ankur\m/50.1K
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 OriginalGriff 223
1 Sascha Lefévre 155
2 Sergey Alexandrovich Kryukov 149
3 ProgramFOX 90
4 Dave Kreskowiak 90
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 7,128
2 Maciej Los 3,440
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | 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