Question
In this exercise, you will total the prices for items selected on an order form, using both a for statement and an if statement. Youll
In this exercise, you will total the prices for items selected on an order form, using both a for statement and an if statement. Youll also add an event listener to the Submit button that supports both modern browsers and older version of Internet Explorer.
- Within the script section enter the following function:
//function to add values of selected check boxes and display total
function calcTotal() {
}
2.Within the function braces, define the following global variables:
var itemTotal = 0;
var items = document.getElementsByTagName(input);
3. Below the global variables, enter the following for statement:
for (var i = 0; i < 5; i++) {
if (items[i].checked) {
itemTotal += (items[i].value * 1);
}
}
4. Below the closing } for the for statement, enter the following statement to write the result to the web document: document.getElementById(total).innerHTML = Your order total is $ + itemTotal + .00;
5. Below the closing } for the function, enter the following code to create an event listener thats compatible with older versions of Internet Explorer.
// add backward compatible event listener to Submit button
var submitButton = document.getElementById(sButton);
if (submitButton.addEventListener) {
submitButton.addEventListener(click, calcTotal, false);
} else if (submitButton.attachEvent) {
submitButton.attachEvent(onclick, calcTotal);
6. Save your work, open index.htm in a browser, check Fried Chicken and Side Salad then click Submit. You should see Your order total is $14.00 on the right hand side of the box.
The text:
Hands-on Project 3-1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started