 |
HTML Help Please Search for the answer to your question before asking it! Thanks.
|
| View previous topic :: View next topic |
| Author |
Message |
iamhaziq
Joined: 24 Jan 2009
Posts: 3
|
| Posted: Sat Jan 24, 2009 9:22 pm Calculating total value |
|
|
Hello,
I'm new with website building, and I'm pretty hopeless with Javascript..
I'm constructing an email submitting form. The form turned out alright, but I failed to calculate the totals.
Can someone help me out? I appreciate it.
The script:
Code:
<!--
function orderTotal(oform, prefix)
{
// set references to fields
var qty = oform[prefix + "_qty"];
var stHold = oform[prefix + "_stHold"];
var price = oform[prefix + "_price"];
var stVis = oform[prefix + "_stVis"];
// only bother if the field has contents
if (qty == "")return;
// if the with is not a number (NaN)
// or is zero or less
// everything goes blank
if(isNaN(qty.value) || (qty.value <= 0))
{
qty.value = "";
stHold.value = "";
}
// else the field is a valid number, so calculate the
// total order cost and put that value in the
// hidden subtotal field
else
stHold.value = (Math.round(qty.value * price.value * 100))/100;
// call the routine which checks if the
// visible subtotal is correct
visTotal(oform, prefix);
}
// checks if the visible subtotal is correct
// ie, if it equals the hidden subtotal field
function visTotal(oform, prefix)
{
var stHold = oform[prefix + "_stHold"];
var stVis = oform[prefix + "_stVis"];
if (stVis.value != stHold.value)
stVis.value = stHold.value;
}
function calcTotal(oform, prefix)
{
var stHold = oform[prefix + "_stHold"];
var stVis = oform[prefix + "_stVis"];
if (stVis.value != stHold.value)
stVis.value = stHold.value
}
// -->
The Basic html:
Code:
<html>
<body>
<table border="1" cellpadding="3">
<!-- table titles -->
<tr style="tableheader">
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
<!-- Tayammum Kit -->
<tr>
<td>Innolux Tayammum Kit</td>
<td><input
type="text"
name="FieldData3_qty"
size="2"
onchange="orderTotal(this.form, 'FieldData3')"
></input></td>
<td><input type="hidden" name="FieldData3_price" value="30.00"></input>RM 30.00</td>
<td align="right">
<input type="hidden" name="FieldData3_stHold"></input>
<input
type="text"
name="FieldData3_stVis"
size="7"
onchange="visTotal(this.form, 'FieldData3')"
></input></td>
</tr>
<!-- Wudu Kit -->
<tr>
<td>Portable Wudu Kit</td>
<td><input
type="text"
name="FieldData4_qty"
size="2"
onchange="orderTotal(this.form, 'FieldData4')"
></input></td>
<td><input type="hidden" name="FieldData4_price" value="6.00"></input>RM 6.00</td>
<td align="right">
<input type="hidden" name="FieldData4_stHold"></input>
<input
type="text"
name="FieldData4_stVis"
size="7"
onchange="visTotal(this.form, 'FieldData4')"
></input></td>
</tr>
<tr>
<td> </td>
<td> </td>
<th>Totals</th>
<td align="right">
<input
type="text"
name="FieldData5_stVis"
size="7"
onchange="calcTotal(this.form, 'FieldData5')"
></input></td>
</tr>
</table>
</body>
</html>
|
|
|
PayneLess Designs
Joined: 28 Feb 2007
Posts: 4289
Location: MS
|
| Posted: Sat Jan 24, 2009 10:56 pm |
|
|
Calculating Order Form Totals
Calculating Order Form Totals 2 |
|
|
iamhaziq
Joined: 24 Jan 2009
Posts: 3
|
| Posted: Mon Feb 02, 2009 1:12 pm |
|
|
| That solves it! Thank you so much. |
|
|
PayneLess Designs
Joined: 28 Feb 2007
Posts: 4289
Location: MS
|
| Posted: Tue Feb 03, 2009 10:15 am |
|
|
| You're welcome. Glad I could help. |
|
|
| |
|
|
|
Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group
|