function submit() {
var values = [];
$("input[type=checkbox]:checked").each(function(){
values.push($(this).next("value").text());
});
alert(values.join());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name = "top" class="checkbox" id="check1" value = "black top"/>
<input type="checkbox" name = "top" class="checkbox" id="check2" value="squish" value = "blue something" />
<button type="button" onclick="submit()">Click Me!</button>
Above is my code for a couple of simple HTML checkboxes. I created a simple button to go along with it, and when I click it I want it to return the values of the checked checkboxes.
However, when I click the button I just get an empty alert box.
The values must not be appended to the array correctly. But I can't work out why, new to HTML/JS/JQuery.
How can I use JS or JQuery to count all the checkboxes.