In this project, you'll create a script that totals purchases and adds tax. Note that your result should work on all modern browsers, but will not work on IE or previous versions of IE 1. In your text editor, open index.htm from the HandsOn Project2-4 folder in the Chapter02 folder. Enter your name and today's date where indicated in the comment section in the document head 2. Open index.htm in your browser. The web page displays a form with five check boxes and a Submit button. Each check box allows users to select an item from a lunch menu. You'll create a script that totals the prices of all the elements a users selects, adds sales tax, and displays the order total in an alert box. 3. Return to your text editor. At the bottom of the document, before the closing tag, enter to create a new script section 4. Within the script section you created in the previous step, enter the following function. 4. Within the script section you created in the previous step, enter the following function. union caleTotal wat isend = document.getElementById("item"); was stendommens gestementById("sem2"); was ten - document.getElementByza ("item"); var items - document.getElementById("item"); vastems - doen.getElementById("item"); (iten.checked) isentosal0 item Total = 0); (ice2.checked) ? central = 9) (scenocal = 0); (tena.checked) ? (ssen osal ) (sten Tesal - 0); (itent.checked) Casentosa - 23) : atentosa! 0); (itens.checked) 1 sentosal ) (sterosal - 0); was walesTaRate - 0.09; var ordeztosal - sentosal(ssentosalsalesTacase) alert(Your order total is - order total); gg Study Textbook Solutions Expert Q&A Study Pack Practice Show all steps: ON Chapter 2, Problem 4HOP Gwer your way document head. Bookmark nuwe wron www 2. Open index.htm in your browser. The web page displays a form with five check boxes and a Submit button. Each check box allows users to select an item from a lunch menu. You'll create a script that totals the prices of all the elements a users selects, adds sales tax, and displays the order total in an alert box. 3. Return to your text editor. At the bottom of the document, before the closing tag, enter to create a new script section 4. Within the script section you created in the previous step, enter the following function. wax Tesal - 0; Les document.getElementById("sen."); Lend document.getElementById("i "); en documen.getElementById(ice ); sent document.getElementById(" "); Itens document.getElementById("items) seni.checked textesal e ntosa Cite .checked seosal sentosa 01 (sed.checkedy s enteral - Tota: 0 send.checked) isentosal in sentosa ) Les checked senteret stort 01 sales taxe - 0.07; destesa se total- sten total sales Taxas escud os de total The calc Total() function starts by creating six local variables-item Total, and one variable storing a reference to each check box element. Each statement in lines 8-12 contains a conditional statement that evaluates whether one of the check boxes on the page is checked. If so, the price corresponding to that check box is added to the item Total variable: if notO is added to the item Total variable. Aner examining the values of all the check boxes, the function declares two additional variables. The sales TaxRate variable specifies the percentage of the purchase price that must be added to the total for tax. In line 14 the value of the orderTotal variable is calculated by first multiplying item Total and sales TaxRate to determine the sales tax amount and then adding that amount to the item Total value. The function ends by generating an alert box additional variables. The sales laxRate vanadie species the percentage or the purchase that must be added to the total for tax. In line 14, the value of the order Total variable is cald by first multiplying item Total and sales TaxRate to determine the sales tax amount and then adding that amount to the item Total value. The function ends by generating an alert box containing the text "Your order total is $" followed by the value of the orderTotal variable. 5. Below the closing } for the calc Total () function, but before the closing tag, enter the follow code to add an event listener. document.getElementById("submit"). addEventListener("click", calcTotal, false); 6. Save your work, refresh or reload index.htm in your browser, click the Fried chicken chec box, and then click the Submit button. As Figure 2-21 shows, the alert boxdisplays a total of $8.56. Click OK Hands-on Project 2-4. Lunch selections Fried chicken (58.00) - Fried halibut (59.00) Hamburger ($8.00) - Grilled salmon ($13.00) Side salad ($6.00) Figure 2-21: Alert box displaying order total 7. Select other items or combinations of items, and verify that the reported total realistically represents the total of the selected items plus 7% tax. In this project, you'll create a script that totals purchases and adds tax. Note that your result should work on all modern browsers, but will not work on IE or previous versions of IE 1. In your text editor, open index.htm from the HandsOn Project2-4 folder in the Chapter02 folder. Enter your name and today's date where indicated in the comment section in the document head 2. Open index.htm in your browser. The web page displays a form with five check boxes and a Submit button. Each check box allows users to select an item from a lunch menu. You'll create a script that totals the prices of all the elements a users selects, adds sales tax, and displays the order total in an alert box. 3. Return to your text editor. At the bottom of the document, before the closing tag, enter to create a new script section 4. Within the script section you created in the previous step, enter the following function. 4. Within the script section you created in the previous step, enter the following function. union caleTotal wat isend = document.getElementById("item"); was stendommens gestementById("sem2"); was ten - document.getElementByza ("item"); var items - document.getElementById("item"); vastems - doen.getElementById("item"); (iten.checked) isentosal0 item Total = 0); (ice2.checked) ? central = 9) (scenocal = 0); (tena.checked) ? (ssen osal ) (sten Tesal - 0); (itent.checked) Casentosa - 23) : atentosa! 0); (itens.checked) 1 sentosal ) (sterosal - 0); was walesTaRate - 0.09; var ordeztosal - sentosal(ssentosalsalesTacase) alert(Your order total is - order total); gg Study Textbook Solutions Expert Q&A Study Pack Practice Show all steps: ON Chapter 2, Problem 4HOP Gwer your way document head. Bookmark nuwe wron www 2. Open index.htm in your browser. The web page displays a form with five check boxes and a Submit button. Each check box allows users to select an item from a lunch menu. You'll create a script that totals the prices of all the elements a users selects, adds sales tax, and displays the order total in an alert box. 3. Return to your text editor. At the bottom of the document, before the closing tag, enter to create a new script section 4. Within the script section you created in the previous step, enter the following function. wax Tesal - 0; Les document.getElementById("sen."); Lend document.getElementById("i "); en documen.getElementById(ice ); sent document.getElementById(" "); Itens document.getElementById("items) seni.checked textesal e ntosa Cite .checked seosal sentosa 01 (sed.checkedy s enteral - Tota: 0 send.checked) isentosal in sentosa ) Les checked senteret stort 01 sales taxe - 0.07; destesa se total- sten total sales Taxas escud os de total The calc Total() function starts by creating six local variables-item Total, and one variable storing a reference to each check box element. Each statement in lines 8-12 contains a conditional statement that evaluates whether one of the check boxes on the page is checked. If so, the price corresponding to that check box is added to the item Total variable: if notO is added to the item Total variable. Aner examining the values of all the check boxes, the function declares two additional variables. The sales TaxRate variable specifies the percentage of the purchase price that must be added to the total for tax. In line 14 the value of the orderTotal variable is calculated by first multiplying item Total and sales TaxRate to determine the sales tax amount and then adding that amount to the item Total value. The function ends by generating an alert box additional variables. The sales laxRate vanadie species the percentage or the purchase that must be added to the total for tax. In line 14, the value of the order Total variable is cald by first multiplying item Total and sales TaxRate to determine the sales tax amount and then adding that amount to the item Total value. The function ends by generating an alert box containing the text "Your order total is $" followed by the value of the orderTotal variable. 5. Below the closing } for the calc Total () function, but before the closing tag, enter the follow code to add an event listener. document.getElementById("submit"). addEventListener("click", calcTotal, false); 6. Save your work, refresh or reload index.htm in your browser, click the Fried chicken chec box, and then click the Submit button. As Figure 2-21 shows, the alert boxdisplays a total of $8.56. Click OK Hands-on Project 2-4. Lunch selections Fried chicken (58.00) - Fried halibut (59.00) Hamburger ($8.00) - Grilled salmon ($13.00) Side salad ($6.00) Figure 2-21: Alert box displaying order total 7. Select other items or combinations of items, and verify that the reported total realistically represents the total of the selected items plus 7% tax