I've written some JQuery code to iterate over some checkboxes on an ASP.Net web page, and am seeing 2 very strange problems with the if statement embedded in the $.each function. The code is selecting my checkboxes just fine, and as the code iterates through the $.each function I can clearly see that the objValue.checked is true or false, appropriately, depending on if I checked the checkbox or not. The problems that I am seeing are: 1) that it always falls into my if statement (even when the value of objValue.checked is false), and 2) the value of my availableInstalls variable is never decremented, even though I can see in debug mode that it hits the "availableInstalls = availableInstalls - 1" line of code. Anyone know what may be causing this behavior?
$(document).ready(function() {
$(".installsoftwarecb").click(function() {
var availableInstalls = 10;
var checkBoxes = $(".installsoftwarecb input[type='checkbox']");
$.each(
checkBoxes, function(intIndex, objValue) {
if (objValue.checked) {
availableInstalls = availableInstalls - 1;
}
});
});
});