Get CheckBoxList Values Using jQuery
- Published on
- -1 min read
To be able to retrieve values from a ASP.NET CheckBoxList control or a group of HTML checkboxes, use the following jQuery:
$(document).ready(function () {
var checkboxValues = [];
$('#<%=MyCheckBoxList.ClientID %> input[type=checkbox]').click(function () {
$('input[type=checkbox]:checked').each(function () {
checkboxValues.push(this.value);
});
});
var values = checkboxValues.toString(); //Output Format: 1,2,3
});
If you do use this code snippet on a CheckBoxList, take a look that this article on how to create a custom CheckBoxList control with a value attribute.
Before you go...
If you've found this post helpful, you can buy me a coffee. It's certainly not necessary but much appreciated!
Leave A Comment
If you have any questions or suggestions, feel free to leave a comment. Your comment will not only help others, but also myself.