Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a javascript problem i need solved need to calculate the price for a new car. Us

ID: 3576013 • Letter: A

Question

a javascript problem i need solved need to calculate the price for a new car. Use a textbox for the Last Name. You must verify that the user has entered the Last Name. If a name is not present, display an appropriate message and place the cursor in the textbox. The Customer ID is 5 digits. If the Customer ID is not numeric, display an appropriate message, clear the textbox, and place the cursor in the textbox. If the Customer ID is not 5 digits, display an appropriate message, clear the textbox, and place the cursor in the textbox. The Customer Code is derived by placing the first character of the Last Name in front of the Customer ID. For example if the Customer ID is 12345 and the Last Name is Apple, the Customer Code is A12345. The Base Price must be numeric and greater than 0. If the Base Price is not numeric, display an appropriate message, clear the textbox, and place the cursor in the textbox. If the Base Price is not greater than 0, display an appropriate message, clear the textbox, and place the cursor in the textbox. The user may select any of the checkboxes. You must add together the option costs and display the amount using two decimal places in the Total Options Cost textbox. The Subtotal is derived by adding the Base Price, Total Options Cost and $800 for the Destination & Freight charges. Format the Subtotal to two decimal places. You must check to see that one of the radio buttons for Dealer Discount has been selected. If a radio button has not been selected, display an appropriate message. If Yes was selected, multiply the Subtotal by 12% to compute the discount. If No was selected, no discount is given. Place this amount in the Dealer Discount textbox. Format the Dealer Discount to two decimal places. To calculate the Final Cost subtract the Dealer Discount from the Subtotal. Format the Final Cost to two decimal places. Please use a submit button to call a function to check the fields, calculate various fields and create a cookie. Remember to format the Total Options Cost, Subtotal, Dealer Discount, and Final Cost to 2 decimal places. Save the Last Name and Final Cost in a cookie. Set the expiration date for the cookie to 2 months. Must be 2 months not 60 days. After a cookie is set, display an appropriate message. here is the form Student Name Last Name: Customer ID: Customer Code: Base Price: What options do you want? Stereo System ($1,050) Leather Interior ($3,000) Remote Keyless Entry ($750) Fuel Injection ($2,500) Wheel Package ($3,500) Total Options Cost: Subtotal: Dealer Discount Yes No Dealer Discount Amount: Final Cost:

Explanation / Answer

<!DOCTYPE html>
<html>
<head>
   <script>
        function validateForm() {
      
           /* Validate Last Name*/
            var lastName = document.forms["myForm"]["lastName"].value;
           if (lastName == "") {
                  document.forms["myForm"]["lastName"].focus();
                  document.forms["myForm"]["lastName"].select();
                  return false;
           }

          
            /*Validate Customer ID and generate Customer Code */
           var customerID = document.forms["myForm"]["customerID"].value;
           var customerCode = "";

           if (customerID == "" || isNaN(customerID) || customerID.length != 5) {
               document.forms["myForm"]["customerID"].focus();
               document.forms["myForm"]["customerID"].select();
                document.forms["myForm"]["customerID"].value = "";
                 return false;
           } else {
               customerCode = lastName[0] + customerID;
               document.getElementById("customerCode").innerHTML = customerCode;
           }
          
          
            /* Validate base price */
            var basePrice = document.forms["myForm"]["basePrice"].value;

           if (basePrice == "" || isNaN(basePrice) || basePrice < 0) {
               document.forms["myForm"]["basePrice"].focus();
               document.forms["myForm"]["basePrice"].select();
                document.forms["myForm"]["basePrice"].value = "";
                 return false;
           }
           basePrice = Number(basePrice).toFixed(2);
            document.forms["myForm"]["basePrice"].value = basePrice;
          
          
          
            /* Find out optional items and calculate their total */
          
            var prices = {'stereoSystem':1050.00, 'leatherInterior':3000.00, 'remoteKeylessEntry':750.00, 'fuelInjection':2500.00, 'wheelPackage':3500.00};
          
            var selectedOptions = document.forms["myForm"]["subItems"];
            var subTotal = Number(basePrice) + 800.00;

            for (var intLoop = 0; intLoop < selectedOptions.length; intLoop++) {
               if ((selectedOptions[intLoop].selected || selectedOptions[intLoop].checked)) {
                  subTotal = subTotal + prices[selectedOptions[intLoop].value];
               }
            }
            subTotal = Number(subTotal).toFixed(2);
            document.getElementById("subTotal").innerHTML = subTotal;


           /* Findout out whether discount can be calculated*/
            var discountAmount = 0;
            var hasDiscount = false;
            var discountRadios = document.getElementsByName('discountRadio');

              if (discountRadios[0].checked) {
                hasDiscount = true;
              }
              if (hasDiscount) {
                discountAmount = subTotal * 0.12;
              }
            discountAmount = Number(discountAmount).toFixed(2);
              document.getElementById("discountAmount").innerHTML = discountAmount;


           /* Calculating final Amount */
              var finalAmount = subTotal - discountAmount;
            finalAmount = Number(finalAmount).toFixed(2);
           document.getElementById("finalAmount").innerHTML = finalAmount;


           /* Setting cookies */
           var expiryDate = new Date();
           expiryDate.setMonth(expiryDate.getMonth() + 2);

            document.cookie = "lastName="+lastName+"; expires = "+expiryDate+";path=/";
           document.cookie = "finalAmount="+finalAmount+"; expires = "+expiryDate+";path=/";          
          
            return false;
       }
      
     
    </script>
</head>
<body>
    <form name="myForm">
        <table cellspacing="2" cellpadding="2" border="1">
           <tr>
              <td align="right">Last Name</td>
              <td><input type="text" name="lastName" /></td>
           </tr>

           <tr>
              <td align="right">Customer ID</td>
              <td><input type="text" name="customerID" pattern="[0-9]{5}"/></td>
           </tr>

           <tr>
              <td align="right">Customer Code</td>
              <td><label id="customerCode" ></label></td>
           </tr>

           <tr>
              <td align="right">Base Price</td>
              <td><input type="text" name="basePrice"/></td>
           </tr>

           <tr>
              <td align="right">Optional Items</td>
              <td>
                <input type="checkbox" name="subItems" value="stereoSystem" />Stereo System ($1050)<br />
                <input type="checkbox" name="subItems" value="leatherInterior" />Leather Interior ($3000)<br />
                <input type="checkbox" name="subItems" value="remoteKeylessEntry" />Remote KeyLess Entry ($750)<br />
                <input type="checkbox" name="subItems" value="fuelInjection" />Fuel Injection ($2500)<br />
                <input type="checkbox" name="subItems" value="wheelPackage" />Wheel Package ($3500)<br />
              </td>
           </tr>

           <tr>
             <td align="right">Sub Total</td>
              <td><label id="subTotal"></label></td>
           </tr>

           <tr>
             <td align="right">Do you have a Dealers discount ? </td>
             <td>
               <input type="radio" name="discountRadio" value="yes"> Yes<br>
               <input type="radio" name="discountRadio" value="nope" checked> No<br>
             </td>
           </tr>

           <tr>
             <td align="right">Discount Amount</td>
              <td><label id="discountAmount"></label></td>
           </tr>

           <tr>
             <td align="right">Final Amount</td>
              <td><label id="finalAmount"></label></td>
           </tr>

           <tr>
              <td align="right"></td>
              <td><input type="submit" value="Submit" /></td>
           </tr>

        </table>
     </form>
</body>
<html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote