Question
Part 3; using form values for computation with JavaScript: Copy the order form from Lab Exercise 2, Part 3 to l4p3.html. (You can use the
Part 3; using form values for computation with JavaScript: Copy the order form from Lab Exercise 2, Part 3 to l4p3.html. (You can use the Unix command cp l2p3.html l4p3.html to do this or copy it locally and upload the copy with your SFTP tool.) Make a link to this new file from your index page.
Add JavaScript to your program to compute the total cost of the order. The total cost will be the sum of the price of each item times the quantity ordered times 1.07 to allow for taxes. Use a JavaScript confirm() call to display "The total cost of your order is (whatever the cost is)." The confirm() function displays a message box with your message and buttons for "OK" and "Cancel." It returns true of the "OK" button is clicked and false if the cancel button is clicked.
If the user of your form clicks OK, the form should be submitted to formtest.php as before. However, if the user clicks "Cancel" the form should not be submitted. See Part 2 for a strong hint on how to do this.
Your computed answer may not look like a dollar amount because JavaScript numbers are floating point. That is OK; you need not correct it. If the messy output bothers you, check JavaScript's toFixed function. It is still possible for your answer to be incorrect in the last penny because toFixed() truncates rather than rounding. That is OK too, but if you want to be exactly correct, add just under 1/2 cent (0.0049) to your computed value before calling toFixed().
Help me fix my code this is what I have:
function total() {
var plan = document.getElementById("numOfPlan").value;
var chisels = document.getElementById("numOfChisels").value;
var pitchforks = document.getElementById("numOfPitchforks").value;
var totalPriceOfPlaners = plan;
var totalPriceOfChisels = chisel;
var totalPriceOfPitchforks = pitch;
var totalPrice = totalPriceOfPlaners + totalPriceOfChisels + totalPriceOfPitchforks * 1.07;
return confirm("The total cost of your order is $" + totalPrice);
}
Lab Exercise 2 Part 3
h1 { font-family:sans-serif;
text-align: center; }
h2{ font-family:sans-serif;
font-style:italic;
text-align: left; }
p { font-family: sans-serif;
font-size: 12px;}
Order Form
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