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.

  1. 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

Hands-on Project 3-1

Lunch selections

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!