Ok so I do this:
<input type="checkbox" class="checkBoxClass" value="0" />
<input type="checkbox" class="checkBoxClass" value="1" />
<input type="checkbox" class="checkBoxClass" value="2" />
Then in javascript/jquery I'm trying to do something like this:
$('#btnHtml').click(function(){
for( var checks=''; $('.checkBoxClass:checked').val() ){
var checks = checks+', ';
}
});
Let's say all of those checkboxes are checked, how can I get var checks to be a string of '0, 1, 2' ?
Still trying to get used to the for() in JS, it might be the completely wrong way of going about it. Not sure how to do this.
Functional programming:
var str = $('.checkBoxClass:checked').map(function() {
return this.value;
}).get().join();
Reference: .map, .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