Question

develop and test an html document that has text boxes for apples orange and banana, along...

develop and test an html document that has text boxes for apples orange and banana, along with a submit button. these boxes take a number which is purchased number of the particular fruit. each of the text boxes should have its own onclick event handler. these handlers must add the cost of their fruit to a total cost. an event handler for the submit button must produce an alert window with the message: your total cost is $xyz id the total cost of the chosen fruit, including 6 percent sales tax. this handler must return false

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SourceCode:

<!DOCTYPE html>
<html>
<head>
   <title>Calculate Cost</title>
<script>
   //Initializing the variable
   let totalCost = 0;
   //function to add the Apple cost to total cost
   function addApple() {
       let numOfApple = document.getElementById("apple").value;
       totalCost = totalCost + (5 * numOfApple);
   }
   //function to add the Orange cost to total cost
   function addOrange() {
       let numOfOrange= document.getElementById("orange").value;
       totalCost = totalCost + (4 * numOfOrange);
   }
   //function to add the Banana cost to total cost
   function addBanana() {
       let numOfBanana= document.getElementById("banana").value;
       totalCost = totalCost + (8 * numOfBanana);
   }
   //function to calculate the total cost inclusing 6% tax
   function displayTotal() {
       let tax = totalCost * (6/100);
       totalCost = totalCost + tax;
       alert("Total cost is : $" + totalCost);

   }

</script>
</head>
<body>
<input type="text" id="apple" onclick="addApple()"><br>
<input type="text" id="orange" onclick="addOrange()"><br>
<input type="text" id="banana" onclick="addBanana()"><br>
<button onclick="displayTotal()">Submit</button>
</body>
</html>

OUTPUT

Add a comment
Know the answer?
Add Answer to:
develop and test an html document that has text boxes for apples orange and banana, along...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Develop and test an HTML document that has text boxes for apple (69 cents each), orange...

    Develop and test an HTML document that has text boxes for apple (69 cents each), orange (59 cents each), and banana (49 cents each), along with a Submit button. These text boxes take a number, which is the purchased number of the particular fruit. Add a max property value of 99 and a min property value of 0. Add event handlers using the min and max properties to check on values input through the text boxes of the document to...

  • HELP! Event Handling- Develop an event handler to handle onclick Form Validation event when a user...

    HELP! Event Handling- Develop an event handler to handle onclick Form Validation event when a user clicks the submit button on the Survey Form. The event handler should validate the following: o The Name tesxt box should contain only Alphabets. o The Address text boxes should contain only appropriate numeric, alphabet or alphanumeric characters o Make sure at least two checkboxes are checked. o Make sure a radio button option is selected. o The Email Address should be valid. Validate...

  • Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum...

    Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1.      Open the HTML and JavaScript files below: 2.      In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...

  • Develop a form in the HTML document containing the following input entries: First Name (use single-line...

    Develop a form in the HTML document containing the following input entries: First Name (use single-line text input) Last Name Gender (use radio buttons) Email Address Telephone Number Sport Interests (use checkbox with at least four different sports items) Preferred Contact Time (use select boxes with Anytime, Morning, Afternoon, and Evening as the four items) Comments (use textarea control) Your page must also include submit and reset buttons! Also use CSS to stylze it and use javascript to validate the...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Develop an HTML form that could be used to enter your book information (Books, Authors, and...

    Develop an HTML form that could be used to enter your book information (Books, Authors, and Publishers) start with the HTML/JavaScript template provided Expand upon it! What field information would you enter into a system? Have your form use more then just character text fields ... radio buttons, pick lists, and other elements make your form easier to use and you don't need to do lots of JavaScript checks. What fields would be mandatory ... which could be left blank?...

  • can you do this js and html question. ill give you the html and js and...

    can you do this js and html question. ill give you the html and js and css files just fix my error use if and else like what i did dont use switch just fix my erorr. <!DOCTYPE html> <!-- Webpage HTML document for Lab 4. Authors: Amirhossein Chinaei, Andriy Pavlovych For: EECS 1012, York University, Lassonde School of Engineering --> <html lang="En"> <head> <meta charset="UTF-8"> <!-- title for web page --> <title> EECS1012: Lab 4 - Computational Thinking </title>...

  • Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on...

    Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on the client side before it is submitted to the server. It is done everywhere because it is fast and it gives you a great deal of flexibility in how you handle errors insofar as the GUI is concerned. Attached is an image of some code I wrote (so Blackboard can't mess it up). Some things to notice that will help you with the lab....

  • given below are the project description and their Html and css files i need javascript according...

    given below are the project description and their Html and css files i need javascript according to the project and other files! WEB230 - JavaScript 1 Assignment 6b - Event Delegation Before starting, study the HTML and open it in a browser so that you understand the structure of the document. You will add functionality to perform several tasks in our shopping list app. Clicking the red "X" at the right of an item will delete that item. Clicking on...

  • i need the code that goes within the <script> opening and closing following the insturctions of...

    i need the code that goes within the <script> opening and closing following the insturctions of the insturctions of the pasted assignment screen shots please. <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 3 Hands-on Project 3-1 Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>Hands-on Project 3-1</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 3-1 </h1> </header> <article> <h2>Lunch selections</h2> <form> <input type="checkbox" id="item1" value="8" /> <label for="item1">Fried chicken ($8.00)</label> <input type="checkbox"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT