Here you go - it now complains that f5 isn't defined (which sort of makes sense as I used to use that to calculate my totals).
I could remove the totaliser line (line 135) but no idea what to put in it's place.
As for why I'm reading a value from a table, have a look at the file in IE and it should make more sense. This is about choosing a base product from a choice of 4, and then adding various options.
Radio boxes are used for the initial selection, and then checkboxes for the rest. The total then displays the price for your selection.
var GrandTotal = f1 + total, GrandTotalW = w1 + totalWholesale;Oh and if you want to make Truffy happy and/or stick to the standards, you can change the .innerHTML bits in the loop to .firstChild.nodeValue
var checkBoxes = getCheckboxes,should read:
var checkBoxes = getCheckboxes(),Note the brackets - they assign the return value of the function to the variable checkBoxes, rather than assigning it the function itself.
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 .