In Lab 5.2 you added a number of potentially
useful elements to your order form. It is now time to take advantage of these
elements so that we can incorporate the information that they provide into the
resulting confirmation page. This involves, first, retrieving and saving the
data from the form elements, and then writing the data out as part of the
resultant page. As before, you should attempt each of these exercises
one at a time, and verify that your changes work as expected before
continuing with the next exercise.
|
|
- Edit your order form now so that it displays the following as part of the order confirmation page:
- the country
- the type of credit card
- the credit card number
- Look at the code in function "submitForm" that calculates the subtotal cost of the order. This calculation uses variables that represent the numeric quantities entered for each item (Qty1Num, Qty2Num, etc.), and some numeric literals ("4.95") representing the prices of the items. From a stylistic standpoint, "hard coding" such values into a script is not a great idea, since any change in the prices involves making error-prone changes to the script.
A (slightly) better approach is to save the price value in hidden input fields, and then to have the script retrieve and use those values in its calculations. Let make this change now, as follows:
- Create six "hidden" fields and place them anywhere within the "Order" form.
You can name the fields whatever you like (something meaningful, like "Price1", would do),
and give them values that match those used in our subtotal calculation.
- Revise function "submitForm" so that it stores the values
(in floating point numeric form!) from these fields in variables,
and then uses those variables to calculate the subtotal for the order.
- Extend function "submitForm" so that it calculates sales tax on the purchase
price and that the tax is both added in to the total cost and displayed explicitly on the order confirmation page.
|