 |
|
|
| 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>
|
Last edited by iamhaziq on Mon Feb 02, 2009 1:09 pm; edited 1 time in total |
|
PayneLess Designs

Joined: 28 Feb 2007 Posts: 4289 Location: MS
|
|
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. |
|
|
|
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
|
|
|
|
|
 |
|
|
|
|
|
|
|