Home › Forums › CSS › Editable Invoice –including tax to total › Re: Editable Invoice –including tax to total
November 17, 2010 at 10:39 pm
#74743
jfreehill
Member
Forget that last post, I should’ve looked at what you were actually using. Sorry about any confusion caused. All you need to do is add a bit to update_total and a small event checker for the checkbox. Below is the code you should actually use:
function update_total() {
var total = 0, tax = 0, taxRate = 0.0575;
$('.price').each(function(i){
price = $(this).html().replace("$","");
if (!isNaN(price)) total += Number(price);
});
total = roundNumber(total,2);
$('#subtotal').html("$"+total);
//will change value of total only if taxbox is checked, otherwise
//it will subtract tax from the total, which defaults to 0
if($('#taxbox:checked')) {
tax = total * taxRate;
total += roundNumber(tax,2);
} else {
total -= tax;
}
$('#total').html("$"+total);
update_balance();
}
Then, towards the bottom of the script where all the other event handlers are inside the document ready function, put this:
$('#taxbox').change(function(){
update_total();
});
Hopefully that works correctly. You may want to add a box the html to show what the tax is or note the addition of taxes just so anybody else seeing it isn’t confused.