Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETJavascript
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/49.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 &lt; 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 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 498
2 Tadit Dash 420
3 sanket saxena 337
4 Zoltán Zörgő 230
0 Sergey Alexandrovich Kryukov 11,800
1 OriginalGriff 7,225
2 Peter Leow 5,009
3 Abhinav S 3,893
4 Maciej Los 3,575


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