I have a checkboxlist control and would like to get all the checkbox values that are checked concatenated into a string separated by '-'. Is there any functions for this? Ex:
$('#checkboxes input[type=checkbox]:checked').concat('-');
I have a checkboxlist control and would like to get all the checkbox values that are checked concatenated into a string separated by '-'. Is there any functions for this? Ex:
$('#checkboxes input[type=checkbox]:checked').concat('-');
I think your best bet is
$('#checkboxes input[type=checkbox]:checked').map(function() {
return $(this).val();
}).get().join('-');
Basically, you're applying a function to each item that returns its value. Then you assemble the result into a string.
Check out this previous post. Perhaps using the map()
function will work for you.
$('#checkboxes input[type=checkbox]:checked').map(function() {
return $(this).val();
}).get().join('-');
That kind of depends on what you are trying to do. For example -
var list = ''
$('#checkboxes input[type=checkbox]:checked').each(function(){
list += $(this).val() + '-'
});
Would give you a list with dash separated values but if you are looking to do this for form processing/submission, check into .serialize()