KCTechNet
asked on
count or sum of checked boxes in a table
I have a table setup with two columns (side1 and side2).
<table border = "1" width="100%" id="Table1">
<td class = 'Side1'>checkbox is here</td> <td class = 'Side2'>checkbox is here</td>
I need to make sure that at least one checkbox is checked on side1 and at least one is checked on side2.
I tried the following but I am getting a syntax error somewhere...I don't even know if this would be the correct way to do it.
<table border = "1" width="100%" id="Table1">
<td class = 'Side1'>checkbox is here</td> <td class = 'Side2'>checkbox is here</td>
I need to make sure that at least one checkbox is checked on side1 and at least one is checked on side2.
I tried the following but I am getting a syntax error somewhere...I don't even know if this would be the correct way to do it.
var sideTotal = [];
$('#table1 .Side1').each(function(){
sideTotal[0]+= $(this) :checked.val();
});
alert(sideTotal[0]);
ASKER
Would't this return the count of all "Side1" and "Side2", regardless of checked or not?
Well, if it does, then I have a bigger problem because I get an alert with zero.
Well, if it does, then I have a bigger problem because I get an alert with zero.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I needed each one seperately, but that gave me what I needed. Thanks.
var canContinue = 1;
var n
n = $('.Side1', '#Table1').find(":checkbox:checked").size();
if (n == 0) {
alert('You need to select at least one item in the first column');
canContinue = 0;
}
n = $('.Side2', '#Table1').find(":checkbox:checked").size();
if (n == 0) {
alert('You need to select at least one item in the second column');
canContinue = 0;
}
Open in new window