vmars316
05-15-2010, 04:14 PM
Greetings;
In the following, what causes the js to create a new page,
for writing the "document.writeln" onto:
31: document.writeln("Price: $" + total_price + "<br>");....
Thanks...vmars316
---START--
1: <html>
2:
3: <head>
4: <title>JS input example.</title>
5: <script language="JavaScript">
6: <!--
7: /* Start of round_total function.
8: */
9: function round_total (c) {
10: var pennies = c * 100;
11: pennies = Math.round(pennies);
12: var strPennies = "" + pennies;
13: var len = strPennies.length;
14: return parseFloat(strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len));
15: }
16: // End of round_total function.
17:
18: /* Start of generate_page function. */
19: function generate_page (form) {
20: tax = 0.08;
21: delivery_p = 2.99;
22: var odate = new Date();
23: var qty = form.quantity.value;
24: var product_v = new String(form.product.value);
25: var total_price = product_v.substr(product_v.indexOf("$") + 1, product_v.length - product_v.indexOf("$"));
26: var price_without_tax = round_total(qty * total_price);
27: var ttax = round_total(price_without_tax * tax);
28: var delivery = round_total(qty * delivery_p);
29: var total_p = round_total(price_without_tax + ttax + delivery);
30: document.writeln("Quantity: " + qty + "<br>");
31: document.writeln("Price: $" + total_price + "<br>");
32: document.writeln("Tax: $" + ttax + "<br>");
33: document.writeln("Delivery: $" + delivery + "<br>");
34: document.writeln("Total: $" + total_p + "<br>");
35: document.writeln("Order placed on: " + odate.toGMTString());
36: }
37: // End of generate_page function.
38:
39: -->
40: </script>
41: </head>
42:
43: <body>
44:
45: <form>
46: <p>Product: <select name="product" size="1">
47: <option value="Brown Jacket - Size 35 - $58.99">Brown Pants - Size 31 - $58.99</option>
48: <option value="Blue Shirt - Size 32 - $69.99">Blue Shirt - Size 32 - $69.99</option>
49: </select><br>
50: Quantity: <input type="text" name="quantity" size="18" value="1"><br>
51: <input type="submit" value="Submit" name="submit" onClick="generate_page(this.form)"><input
52: type="reset" value="Reset" name="reset"></p>
53: </form>
54: </body>
55: </html>
---END----
In the following, what causes the js to create a new page,
for writing the "document.writeln" onto:
31: document.writeln("Price: $" + total_price + "<br>");....
Thanks...vmars316
---START--
1: <html>
2:
3: <head>
4: <title>JS input example.</title>
5: <script language="JavaScript">
6: <!--
7: /* Start of round_total function.
8: */
9: function round_total (c) {
10: var pennies = c * 100;
11: pennies = Math.round(pennies);
12: var strPennies = "" + pennies;
13: var len = strPennies.length;
14: return parseFloat(strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len));
15: }
16: // End of round_total function.
17:
18: /* Start of generate_page function. */
19: function generate_page (form) {
20: tax = 0.08;
21: delivery_p = 2.99;
22: var odate = new Date();
23: var qty = form.quantity.value;
24: var product_v = new String(form.product.value);
25: var total_price = product_v.substr(product_v.indexOf("$") + 1, product_v.length - product_v.indexOf("$"));
26: var price_without_tax = round_total(qty * total_price);
27: var ttax = round_total(price_without_tax * tax);
28: var delivery = round_total(qty * delivery_p);
29: var total_p = round_total(price_without_tax + ttax + delivery);
30: document.writeln("Quantity: " + qty + "<br>");
31: document.writeln("Price: $" + total_price + "<br>");
32: document.writeln("Tax: $" + ttax + "<br>");
33: document.writeln("Delivery: $" + delivery + "<br>");
34: document.writeln("Total: $" + total_p + "<br>");
35: document.writeln("Order placed on: " + odate.toGMTString());
36: }
37: // End of generate_page function.
38:
39: -->
40: </script>
41: </head>
42:
43: <body>
44:
45: <form>
46: <p>Product: <select name="product" size="1">
47: <option value="Brown Jacket - Size 35 - $58.99">Brown Pants - Size 31 - $58.99</option>
48: <option value="Blue Shirt - Size 32 - $69.99">Blue Shirt - Size 32 - $69.99</option>
49: </select><br>
50: Quantity: <input type="text" name="quantity" size="18" value="1"><br>
51: <input type="submit" value="Submit" name="submit" onClick="generate_page(this.form)"><input
52: type="reset" value="Reset" name="reset"></p>
53: </form>
54: </body>
55: </html>
---END----