I am trying to loop the values of a multiselect checkboxes so that I can split the array and post them as one string. In PHP you can just say:
implode(",", $_POST['usage'])
to get a comma separated string. How would I get the same in javascript or using jquery for the source below.
<input type="checkbox" name="usage[]" id="usage-ContentManagement" value="Content Management">
<input type="checkbox" name="usage[]" id="usage-Personal" value="Personal">
<input type="checkbox" name="usage[]" id="usage-Business" value="Business">
<input type="checkbox" name="usage[]" id="usage-SmallBusiness" value="Small Business">
I have tried $('[name="usage[]"]').val() but it will always give “Content Management” even if the checkbox is not selected.
Iterate over the checkboxes and store their values in an array. Then “implode” this array.