 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
SquareOne123
Joined: 25 Jan 2007 Posts: 2
|
Posted: Thu Jan 25, 2007 6:49 am create a simple price calculator |
|
|
|
I would like to create a simple price calculator, basically
QUANTITY x PRICE + a flat rate SHIPPING/HANDLING = TOTAL
But then I would also like to be able to show/calculate a discount if they purchase 25 or more of one item. Can someone help me write this?
Thanks! |
|
Pattons3rd

Joined: 28 Dec 2006 Posts: 1212 Location: Colorado
|
Posted: Sun Jan 28, 2007 5:47 pm |
|
|
|
Here is something I got from the 24-Hour HTML Cafe:
| Quote: |
<script language="JavaScript">
<!--
function CalculateTotals(){
f=document.orderform;
f.total1.value=parseInt(f.qty1.value)*50;
f.total2.value=parseInt(f.qty2.value)*295;
f.total3.value=parseInt(f.qty3.value)*395;
f.total4.value=parseInt(f.qty4.value)*750;
f.grandtotal.value=parseInt(f.total1.value)
+parseInt(f.total2.value)
+parseInt(f.total3.value)
+parseInt(f.total4.value)
+parseInt(f.sh.value);}
//-->
</script></head>
<body>
<form name="orderform" method="post" action="formprocessor">
<table border="3"><tr>
<th>Qty</th><th>Part #</th><th>Description</th>
<th>Price</th><th>Total</th></tr>
<tr><td>
<input name="qty1" size="3" OnBlur="CalculateTotals()" /></td>
<td>25791</td><td>Chromated Flywheel Knob</td>
<td align="right">$50</td>
<td><input name="total1" size="7"
OnFocus="document.orderform.qty2.select();
document.orderform.qty2.focus();" /></td></tr>
<tr><td>
<input name="qty2" size="3" OnBlur="CalculateTotals()" /></td>
<td>17557</td><td>Perambulatory Dramograph</td>
<td align="right">$295</td>
<td><input name="total2" size="7"
OnFocus="document.orderform.qty3.select();
document.orderform.qty3.focus();" /></td></tr>
<tr><td>
<input name="qty3" size="3" OnBlur="CalculateTotals()" /></td>
<td>98754</td><td>Triple-Extruded Colorizer</td>
<td align="right">$395</td>
<td><input name="total3" size="7"
OnFocus="document.orderform.qty4.select();
document.orderform.qty4.focus();" /></td></tr>
<tr><td>
<input name="qty4" size="3" OnBlur="CalculateTotals()" /></td>
<td>47594</td><td>Rediculation Kit (Complete)</td>
<td align="right">$750</td>
<td><input name="total4" size="7"
OnFocus="document.orderform.qty1.select();
document.orderform.qty1.focus();" /></td></tr>
<tr><td></td><td></td><td></td>
<td align="right">Shipping and handling:</td><td> $5</td></tr>
<tr><td></td><td></td><td></td>
<td align="right"><b>GRAND TOTAL:</b></td>
<td><input name="grandtotal" size="7"
OnFocus="document.orderform.qty1.select();
document.orderform.qty1.focus();" /></td></tr>
</table>
<input type="hidden" value="5" name="sh" />
<br /><input type="submit" value="Make Purchase" />
</form>
<script language="JavaScript">
<!--
f=document.orderform;
f.qty1.value=0; f.qty2.value=0;
f.qty3.value=0; f.qty4.value=0;
f.total1.value=0; f.total2.value=0;
f.total3.value=0; f.total4.value=0;
f.sh.value=5;
f.grandtotal.value=5;
//-->
</script>
</body></html> |
You can easily change this for your own puposes if you know a little JavaScript and HTML. |
|
SquareOne123
Joined: 25 Jan 2007 Posts: 2
|
Posted: Mon Jan 29, 2007 6:21 am price calculator |
|
|
|
| Thank you so much, Pattons3rd! I can definitely work with this. Thanks! |
|
Pattons3rd

Joined: 28 Dec 2006 Posts: 1212 Location: Colorado
|
Posted: Mon Jan 29, 2007 7:10 am |
|
|
|
| Your very welcome and glad to be of help! |
|
mitchafied
Joined: 03 Feb 2008 Posts: 3
|
Posted: Sun Feb 03, 2008 7:27 pm S.O.S. - JavaScript Caluclator |
|
|
|
Do you know how I would go about creating something that will be suitable for this problem? Thank you any help would be great.
Problem:
Many companies normally charge a shipping and handling charge for purchases. Create a web page that allows a user to enter a purchase price into a text box and includes a JavasScript function that calculates shipping and handling. Add functionality to the script that adds a minimum shipping and handling charge of $1.50 for any purchase that is less than or equal to $25.00. for any order over $25.00, add 10% to the total purchase price for shipping and handling. But do not include the $1.50 minimum shipping and handling charge. The formula for calculating the percentage is price * percent / 100. For example, the formula for calculating 10% of the $50.00 purchase price is 50 * 10 / 100, which results in a shipping and handling charge of $5.00. After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box. |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|