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('-');
I think you want to look at jQuery's .map() functionality (not tested):
$('#checkboxes input[type=checkbox]:checked').map(function() {
return $(this).attr('value');
}).get().join('-');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With