Still not working. I noticed one error myself, you'd referred to a variable as GrandTotalW rather than GrandWTotal, but then I got this next one:
Message: 'parentElement.previousElementSibling.innerHTML' is null or not an object
Line: 126
Char: 9
Code: 0
HTML is attached.
(by the way, this is why I prefer my method, it may be more long winded and cumbersome, but it's a damn site easier to understand and fix when it goes wrong)
<script type="text/javascript"> //Get the values from the table when checkboxes are checked var getCheckboxes = function () { var i, elements = document.getElementsByTagName("input"), max = elements.length, result = []; for (i = 0; i < max; i += 1) { if (elements[i].type === "checkbox") { result.push(elements[i]); } } return result; DeleteComma(result); };
<script type="text/javascript"> function DeleteComma(num) { var temp1 = 0; var xarray = num.split(","); if ( xarray[2] != null ) { temp1 = xarray[0]+xarray[1] +xarray[2]; return temp1 } else if ( xarray[1] != null ) { temp1 = xarray[0] +xarray[1]; return temp1} else {temp1 = xarray[0]; return temp1 } } </script>
var deleteCommas = function (num) { return (num + "").replace(/,/g, ""); };
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; } }Change it to this:
var element, deleteCommas; deleteCommas = function (num) { return (num + "").replace(/,/g, ""); }; for (i = 0; i < max; i += 1) { if (checkBoxes[i].checked) { element = checkBoxes[i].parentElement.previousSibling; total += +deleteCommas(element.innerHTML); element = element.previousSibling; totalWholesale += +deleteCommas(element.innerHTML); } }
stripNonNumeric = function (num) { return (num + "").replace(/[^0-9.]/g, ""); };That way it would remove things like currency symbols or extra spaces or whatnot - anything that isn't a digit or a .