Question: modify your individual project to create and populate an array of products. Create a function that dynamically adds the array values to your products page
modify your individual project to create and populate an array of products. Create a function that dynamically adds the array values to your products page (essentially replacing the static list you created in the Chapter 2 assignment).
Using Hands-On Project 3-1 as a template, change the mechanism for calculating the subtotal of a customer order to incorporate a for loop.
This is my Script.js file but the code is not outpuuting any totals onto the web page
var products = ["Ding Repair Kit ($20.00)", "Fin Box ($12.00)", "UV Cure Epoxy ($8.00)", "Set of Fins ($22.00)", "6 FT. Leash ($15.00)"]; var labels = document.getElementsByTagName("label"); function processProducts() { for (var i = 0; i < 5 ; i++){ labels[i].innerHTML = products[i]; } } if (window.addEventListener) { window.addEventListener("load", processProducts, false); } else if (window.attachEvent) { window.attachEvent("onload", processProducts); }
function calcTotal() { var itemTotal = 0; var salesTaxRate = .06; var items = document.getElementsByTagName("input"); for (var i = 0; i < 5; i++) { if (items[i].checked) { itemTotal += parseInt(items[i].value); } } itemTotal *= 1+ salesTaxRate; document.getElementById("total").innerHTML = "Your Order total is $" + itemTotal.toFixed(2); } var submitButton = document.getElementById("sButton"); if (submitButton.addEventListener) { submitButton.addEventListener("click", calcTotal, false); } else if (submitButton.attachEvent) { submitButton.attachEvent("onclick" , calcTotal); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
