Created
January 23, 2016 10:05
-
-
Save StoneCypher/71246c6c66d017b57ee2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function byId(id) { | |
| return document.getElementById(id); | |
| } | |
| var ckShelf = byId("shelf"), | |
| shelf1 = byId("shelf1"), | |
| shelf2 = byId("shelf2"), | |
| shelf3 = byId("shelf3"), | |
| sTotal = byId("shelfCost"); | |
| var ckDrawer = byId("drawer"), | |
| drawer1 = byId("drawer1"), | |
| drawer2 = byId("drawer2"), | |
| drawer3 = byId("drawer3"), | |
| dTotal = byId("drawerCost"); | |
| var ckDesk = byId("desk"), | |
| desk1 = byId("desk1"), | |
| desk2 = byId("desk2"), | |
| desk3 = byId("desk3"), | |
| deTotal = byId("deskCost"); | |
| var tTotal = byId("taxCost"); | |
| var ckShip = byId("shiptax"), | |
| shTotal = byId("shipCost"); | |
| var gTotal = byId("totalCost"); | |
| var totalInputs = [sTotal, dTotal, deTotal, shTotal, tTotal, gTotal]; | |
| function clearAll() { | |
| document.getElementsByTagName("input") | |
| .map(function(eachInput) { eachInput.checked = false; }); | |
| totalInputs.map( | |
| function(control) { control.value = null; } | |
| ); | |
| } | |
| function setDollarValue(Target, DollarValue) { | |
| Target.value = ("$" + Number(DollarValue).toFixed(2)); | |
| } | |
| function ckCheckedRow(Enabler, c1, c2, c3, Target) { | |
| if (Enabler.checked) { | |
| setDollarValue(Target, 0); | |
| if (c1.checked) { setDollarValue(Target, c1.value); } | |
| else if (c2.checked) { setDollarValue(Target, c2.value); } | |
| else if (c3.checked) { setDollarValue(Target, c3.value); } | |
| } else { | |
| Target.value = null; | |
| } | |
| } | |
| function ckChecked() { | |
| ckCheckedRow(ckShelf, shelf1, shelf2, shelf3, sTotal); | |
| ckCheckedRow(ckDrawer, drawer1, drawer2, drawer3, dTotal); | |
| ckCheckedRow(ckDesk, desk1, desk2, desk3, deTotal); | |
| if (ckShip.checked) { setDollarValue(shTotal, 10); } | |
| else { shTotal.value = null; } | |
| } | |
| function sumInto(Target, Left, Right) { | |
| Target.value = parseInt(Left.value) + parseInt(Right.value); | |
| } | |
| function addTax() { | |
| tTotal.value = ("$" + (0).toFixed(2)); | |
| if (ckShelf.checked) { sumInto(tTotal, tTotal, sTotal); } | |
| if (ckDrawer.checked) { sumInto(tTotal, tTotal, dTotal); } | |
| if (ckDesk.checked) { sumInto(tTotal, tTotal, deTotal); } | |
| } | |
| function grandTotal() { | |
| gTotal.value = ("$" + (0).toFixed(2)); | |
| if (ckShelf.checked) { sumInto(gTotal, gTotal, sTotal); } | |
| if (ckDrawer.checked) { sumInto(gTotal, gTotal, dTotal); } | |
| if (ckDesk.checked) { sumInto(gTotal, gTotal, drTotal); } | |
| if (ckShip.checked) { sumInto(gTotal, gTotal, shTotal); } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment