Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

6. Are my sources reliable?

Answered: 1 week ago

Question

5. Are my sources compelling?

Answered: 1 week ago