Alpha
07-10-2003, 11:53 AM
Please can somebody help me with the following script:
I need to calculate the subtotal, charge 17.5% tax on taxable products only and then total the whole lot together.
Much appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label, button {display:block; margin:1ex}
input {margin-right:1em; width:5em}
-->
</style>
<script type="text/javascript">
<!--
String.prototype.reverse = function () {return this.split('').reverse().join('')};
function Dollars (d) {this.ammount = typeof d == 'number' ? d : Number(d.toString().replace(/[$,]/g, ''))};
Dollars.prototype.valueOf = function () {return this.ammount};
Dollars.prototype.toString = function () {
if (isNaN (this.ammount)) return NaN.toString();
var l = Math.floor(Math.abs(this.ammount)).toString();
var r = Math.round((Math.abs(this.ammount) % 1) * 100).toString();
return [(this.ammount < 0 ? '-' : ''), '$', (l.length > 4 ? l.reverse().match(/\d{1,3}/g).join(',').reverse() : l),'.', (r < 10 ? '0' + r : r)].join('');
}
// -->
</script>
<form action="" onsubmit="return multiply(this)">
<table width="100%" border="0">
<tr>
<td colspan="2" align="center">Tax Rated</td>
</tr>
<tr>
<td><input type="text" id="item1_quantity" onchange="this.form.subtotal_1.value = new Dollars(new Dollars(this.value) * 3.2)">Dollars</td>
<td><input type="text" id="subtotal_1">Result</td>
</tr>
<tr>
<td><input type="text" id="item2_quantity" onchange="this.form.subtotal_2.value = new Dollars(new Dollars(this.value) * 3.6)">Dollars</td>
<td><input type="text" id="subtotal_2">Result</td>
</tr>
<tr>
<td colspan="2" align="center">Tax Zero Rated</td>
</tr>
<tr>
<td><input type="text" id="item3_quantity" onchange="this.form.subtotal_3.value = new Dollars(new Dollars(this.value) * 7.2)">Dollars</td>
<td><input type="text" id="subtotal_3">Result</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="subtotal">Subtotal</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="Tax">Tax</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="Total">Total</td>
</tr>
</table>
</form>
</body>
</html>
I need to calculate the subtotal, charge 17.5% tax on taxable products only and then total the whole lot together.
Much appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label, button {display:block; margin:1ex}
input {margin-right:1em; width:5em}
-->
</style>
<script type="text/javascript">
<!--
String.prototype.reverse = function () {return this.split('').reverse().join('')};
function Dollars (d) {this.ammount = typeof d == 'number' ? d : Number(d.toString().replace(/[$,]/g, ''))};
Dollars.prototype.valueOf = function () {return this.ammount};
Dollars.prototype.toString = function () {
if (isNaN (this.ammount)) return NaN.toString();
var l = Math.floor(Math.abs(this.ammount)).toString();
var r = Math.round((Math.abs(this.ammount) % 1) * 100).toString();
return [(this.ammount < 0 ? '-' : ''), '$', (l.length > 4 ? l.reverse().match(/\d{1,3}/g).join(',').reverse() : l),'.', (r < 10 ? '0' + r : r)].join('');
}
// -->
</script>
<form action="" onsubmit="return multiply(this)">
<table width="100%" border="0">
<tr>
<td colspan="2" align="center">Tax Rated</td>
</tr>
<tr>
<td><input type="text" id="item1_quantity" onchange="this.form.subtotal_1.value = new Dollars(new Dollars(this.value) * 3.2)">Dollars</td>
<td><input type="text" id="subtotal_1">Result</td>
</tr>
<tr>
<td><input type="text" id="item2_quantity" onchange="this.form.subtotal_2.value = new Dollars(new Dollars(this.value) * 3.6)">Dollars</td>
<td><input type="text" id="subtotal_2">Result</td>
</tr>
<tr>
<td colspan="2" align="center">Tax Zero Rated</td>
</tr>
<tr>
<td><input type="text" id="item3_quantity" onchange="this.form.subtotal_3.value = new Dollars(new Dollars(this.value) * 7.2)">Dollars</td>
<td><input type="text" id="subtotal_3">Result</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="subtotal">Subtotal</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="Tax">Tax</td>
</tr>
<tr>
<td></td>
<td><input type="text" id="Total">Total</td>
</tr>
</table>
</form>
</body>
</html>