Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Adding Sales Tax and Other Charges to Jquery Calculation Plugin

1. ## Adding Sales Tax and Other Charges to Jquery Calculation Plugin

Hi there, this is a follow-up question to one I asked @ Stack Overflow, but I couldn't get any further help there.

Basically I have a delivery price estimator that uses the very helpful Jquery Calculation Plugin and a live example of it can be found here: http://jsfiddle.net/mohammadAdil/afk3C/5/

With some help, I managed to have almost everything to work. So far I can display the subtotal and the grand total, which includes a 13% sales tax. I need to be able to also display the actual tax value after the subtotal as well as fuel charge and a late fee (when applicable). In other words, the subtotal should not include the fuel charge and the late fee. I should have the following:

Subtotal = \$amount
Fuel = \$amount
Late Fee = \$amount
Sales tax = 0.13(subtotal + fuel + Late)
Total = subtotal + fuel + + Late + sales tax

I hope it makes some sense.

Here's my javascript from Jsfiddle (Link above):

Code:
```  \$("#FirstHourRate, #HalfHourRate, [rel='eta']").keyup(recalc);

function recalc() {

\$("#subtotal").calc(
// the equation to use for the calculation
"FirstHourRate + (eta-1)*2*HalfHourRate", {
bind: "keyup",
eta: \$("[rel='eta']").sum(),
FirstHourRate: \$("#FirstHourRate"),
HalfHourRate: \$("#HalfHourRate")
}, function(s) {
// return the number as a dollar amount
var gt = s.toFixed(2) * 1.13;
\$("#hst").text("\$" + gt.toFixed(2));
return "\$" + s.toFixed(2);

});
}```
Thanks

• I don't know why you need a plug in to do this - it seems like fairly simple mathematics.

Anyway. If your spans look like this:
Code:
```<div class="span4">
Subtotal : <span id="subtotal"></span><br>
HST: <span id="hst"></span><br>
Fuel: <span id="fuelspan"></span><br>
Late Fee: <span id="late"></span><br>
Sales tax: <span id="taxspan"></span><br>
Total: <span id="total"></span><br>
</div>```
your script could look like this:

Code:
```<script>

\$("#EstimateForm").keyup(recalc);

function recalc() {

\$("#subtotal").calc(
// the equation to use for the calculation
"FirstHourRate + (eta-1)*2*HalfHourRate", {
bind: "keyup",
eta: \$("[rel='eta']").sum(),
FirstHourRate: \$("#FirstHourRate"),
HalfHourRate: \$("#HalfHourRate")
}, function(s) {
// return the number as a dollar amount
var gt = s.toFixed(2) * 1.13;
\$("#hst").text("\$" + gt.toFixed(2));

var fuelcost=\$("#Fuel").val()==""?0:Number(\$("#Fuel").val());
var latefee=\$("#OtherCharges").val()==""?0:Number(\$("#OtherCharges").val());
var tax=(fuelcost+s+latefee)*.13;
\$("#fuelspan").text("\$" +fuelcost);
\$("#late").text("\$" +latefee);
\$("#taxspan").text("\$" +tax.toFixed(2));
var tot=(s + fuelcost + latefee + tax).toFixed(2);
\$("#total").text("\$" + tot);
return "\$" + s.toFixed(2);
});
}

</script>```

• ## Users who have thanked xelawho for this post:

treigh (04-03-2013)

• Thanks @xelawho -- This answers a 2-day long question.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•