Question: I create the cart.html and the cart_validation.js however, it does not work. 1. Write a JavaScript script that validates all user entries for which if

I create the cart.html and the cart_validation.js however, it does not work.

1. Write a JavaScript script that validates all user entries for which if makes sense to do so in the form that permits your customers to choose products and/or services. Be sure to inform the user if any data entry is invalid with an appropriate popup message. Once all input has been entered. A typical display should include a summary of the items ordered, the quantity of each item, and the total cost.

3. Write a JavaScript script that validates all user entries for which it makes sense to do so in the form that permits your customers to give you feedback on their experience with your business. Report to the user if a particular entry is invalid, and be sure to tell the user that everything is OK if that is the case.

Shopping Cart

Shopping Cart

Welcome to bikerChick13 Checkout:

Checkout
Your Cart
120 USD
250 USD
200 USD
E-mail record?
Processing

Thank you for your business. Take a brief survey and tell us about your experience at bikerChick13. Survey

//cartFormValidate.js //Functions to perform data validation on data entered //by the user into the cart form, and to display appropriate //error messages if problems with the data are discovered

function cartFormValidate(cartFormObj) { var quanity = cartFormObj.quanity.value; var email = cartFormObj.email.value; var quanityOK, emailOK;

if (quanity == int){ quanityOK = intValid(quanity); return true; } if (cartFormObj.wantMail.checked) { emailOK = emailValid(email); alert("Warning: The e-mail feature is currently not supported."); } else emailOK = true; return quanityOK && emailOK; }

function intValid(quanity) { if (quanity == "" || isNaN(quanity)) { alert("Error: Please input a number for quanity."); return false; } if (quanity < 0 || quanity > 100) { alert("Error: quanity must be in the range 0-100."); return false; } return true; }

function emailValid(address) { var p = address.search(/.+@.+/); if (p == 0) return true; else { alert("Error: Invalid e-mail address."); return false; } }

//cartFormProcess.js //The "driver" function that handles, at the highest level, //the form data validation and display of the the BMI value

function cartFormProcess() { var cartFormObj = document.getElementById("cartForm"); if (cartFormValidate(cartFormObj)) { var cart = valueOfcart(cartFormObj); if (cartFormObj.details.checked) displayDetails(cartFormObj, cart); else alert("Your Cart Summary: " + calc(cart)); } }

//cartCalculate.js //Functions to perform the cart value calculation, //assuming all data input by the user has been validated

function valueOfCart(cartFormObj) { var hUnit = cartFormObj.helmetUnit. options[cartFormObj.helmetUnit.selectedIndex].text; var jUnit = cartFormObj.jacketUnit. options[cartFormObj.bootUnit.selectedIndex].text; var bUnit = cartFormObj.bootUnit. options[cartFormObj.boottUnit.selectedIndex].text; var helmet = cartFormObj.helmet.value; var jacket = cartFormObj.jacket.value; var boot = cartFormObj.boot.value;

if (hUnit == "small") helmet = smallHelmet(helmet); if (hUnit == "medium") helmet = mediumHelmet(helmet); if (hUnit == "large") helmet = largeHelmet(helmet); if (jUnit == "small") jacket = smallJacket(jacket); if (jUnit == "medium") jacket = mediumHelmet(jacket); if (jUnit == "large") jacket = largeHelmet(jacket); if (bUnit == "small") boot = smallJacket(boot); if (bUnit == "medium") boot = mediumHelmet(boot); if (bUnit == "large") boot = largeHelmet(boot); height /= 100.0; //Convert height from centimeters to meters var bmi = weight/(height*height); //kilograms/(meters*meters) return bmi; }

function smallHelmet(helmet) { var SMALL_HELMET_PRICE = 125.0; return helmet * SMALL_HELMET_PRICE; }

function mediumHelmet(helmet) { var MEDIUM_HELMET_PRICE = 150.0; return helmet * MEDIUM_HELMET_PRICE; }

function largeHelmet(helmet) { var LARGE_HELMET_PRICE = 175.0; return helmet * LARGE_HELMET_PRICE; }

function smallJacket(jacket) { var SMALL_JACKET_PRICE = 225.0; return jacket * SMALL_JACKET_PRICE; }

function mediumJacket(jacket) { var MEDIUM_JACKET_PRICE = 250.0; return jacket * MEDIUM_JACKET_PRICE; }

function largeJacket(jacket) { var LARGE_JACKET_PRICE = 275.0; return jacket * LARGE_JACKET_PRICE; }

function smallBoot(boot) { var SMALL_BOOT_PRICE = 200.0; return boot * SMALL_BOOT_PRICE; }

function mediumBoot(boot) { var MEDIUM_BOOT_PRICE = 200.0; return boot * MEDIUM_BOOT_PRICE; }

function largeBoot(boot) { var LARGE_BOOT_PRICE = 215.0; return boot * LARGE_BOOT_PRICE; }

function calc(cart) { var hUnit = document.getElement("helmetUnit"); var jUnit = document.getElement("jacketUnit"); var bUnit = document.getElement("bootUnit"); var quantity = 0; var subtotal = 0.00; if (hUnit == small && text >0); var total = quantity * (smallHelmet) var text = "$" + subtotal; return text; if (hUnit == medium && text >0); var total = quantity * (mediumHelmet) var text = "$" + subtotal; return text; if (hUnit == large && text >0); var total = quantity * (largeHelmet) var text = "$" + subtotal; return text; if (jUnit == small && text >0); var total = quantity * (smallJacket) var text = "$" + subtotal; return text; if (jUnit == medium && text >0); var total = quantity * (mediumJacket) var text = "$" + subtotal; return text; if (jUnit == large && text >0); var total = quantity * (largeJacket) var text = "$" + subtotal; return text; if (bUnit == small && text >0); var total = quantity * (smallBoot) var text = "$" + subtotal; return text; if (bUnit == medium && text >0); var total = quantity * (mediumBoot) var text = "$" + total; return text; if (bUnit == large && text >0); var total = quantity * (largeBoot) var text = "$" + subtotal; return text; }

function displayDetails(cartFormObj, cart) { var hUnit = cartFormObj.helmetUnit. options[cartFormObj.helmetUnit.selectedIndex].text; var jUnit = cartFormObj.jacketUnit. options[cartFormObj.jackettUnit.selectedIndex].text; var bUnit = cartFormObj.bootUnit. options[cartFormObj.bootUnit.selectedIndex].text; var helmet = cartFormObj.helmet.value; var jacket = cartFormObj.jacket.value; var boot = cartFormObj.boot.value; var text = "Cart Summary " + "Helmet Price: " + helmet + " " + hUnit + " " + "Jacket Price: " + jacket + " " + jUnit + " " + "Boot Price: " + boot + " " + bUnit + " " + "Your Cart Total: " + calc(cart) + " "; if (cart == 0.00) text += "Please enter quantity in appropriate fields. "; else if (cart != 0.00) text += "Thank you for shopping at bikerChick13! "; alert(text); }

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!