Well as it is you'd have to rewrite the table, but this would take the values from the table itself:
javascript code:
var checkBoxes = document.querySelectorAll("input[type=checkbox]"),
max = checkBoxes.length,
i, total = 0, totalWholesale = 0;
for (i = 0; i < max; i += 1) {
if (checkBoxes[i].checked) {
// Get values directly from table cells.
total += +checkBoxes[i].parentElement.
previousElementSibling.innerHTML;
totalWholesale += +checkBoxes[i].parentElement.
previousElementSibling.previousElementSibling.innerHTML;
}
}
edit: just realised the + should be at the start of the variable names, not the end. The + at the start is a forced type conversion; an alternative is to use:
javascript code:
total += parseInt(checkBoxes[i].parentElement.previousElementSibling.innerHTML, 10);
Edit again:
Another thing I thought of was that using jQuery needn't be any hassle - you can just include this line on your page somewhere before your current JS code:
HTML code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
edit3: oo, jQuery 1.5 is out
:OEDITED: 11 Feb 2011 17:41 by CAER