I am hoping to get all the checked checkboxes from my form into an array.
Here is what I did.
$("div.category-panel input:checked").next ('label').text(); perfectly gets all the checked checkboxes but it just shows them together as one text. As an example, checkbox1, checkbox2 and checkbox3 (if checked) would show as checkbox1checkbox2checkbox3.
I was hoping to get these different checkboxes in an array so that I can use them.
$('.submit').on("click", function(e) {
//got all checked checkboxes into 'children'.
children = $("div.category-panel input:checked").next ('label').text();
//Put in array.
var array = [];
var i = 0;
$.each(children, function(key, value){
array.push($(this).text());
});
//Show the array.
for (var i = 0; i < array.length; i++) {
console.log(array[i]);
}
});
HTML, just in case is:-
<div class="category-panel">
<input type="checkbox" name="name_service2" id="tid-46" value="46" checked="checked"> <label class="option" for="edit-tid-46">CheckBox1</label>
<input type="checkbox" name="name_service3" id="tid-47" value="47" checked="checked"> <label class="option" for="edit-tid-47">CheckBox2</label>
<input type="checkbox" name="name_service4" id="tid-44" value="44" checked="checked"> <label class="option" for="edit-tid-44">CheckBox3</label>
<input type="checkbox" name="name_service5" id="tid-48" value="48" checked="checked"> <label class="option" for="edit-tid-48">CheckBox4</label>
</div>