Looping over a bunch of checkboxes SOMETIMES fails. The .each function is NOT entered when some or all boxes are checked so I get the "no checkboxes were checked" alert even though "checked" boxes exist.
$(document).ready(function() {
$("#submitme").click(function() {
var urls = [];
$("#edit :checked").each(function() {
var obj = {};
obj.url = $(this).val();
urls.push(obj);
});
if (0 < urls.length) {
$.post('/myurl', {urls: JSON.stringify(urls)});
}
else {
alert("no checkboxes were checked!");
}
});
});
<div id="edit">
<input type="checkbox" name="first" value="first_url"/>
<input type="checkbox" name="second" value="second_url"/>
<button id="submitme">submit</button>
</div>
ifis messed up.