So I am pretty new to Javascript and trying to get a sales tax item to work for us.
I have things working great but was going the easy route and having just single fields. Essentially I have a amount I type in. If the Tax dropdown is nothing, the Tots field shows the total. If I select MN for Tax, javascript calculates the tax and adds it up.
For example, no tax shows:
Flipping to MN shows:
This works great. However for line items we need these 3 fields in a table where they can add as many rows as possible. They enter the amount but some lines are taxed and others not. Any idea as to how I would modify this code to fit into a table?
$("#Field147").on('change',function(){ CalcTax(); }); //Call CalcTax function when Tax field changed. $("#Field148").on('change',function(){ CalcTax(); }); //Call CalcTax function when Currency field changed. function round(number, places) { number = parseFloat(number, 10); var e = parseInt(places || 2, 10); var m = Math.pow(10, e); return Math.floor(number * m) / m; }; function CalcTax(){ var tax = 0.07125; var totaltax = 0.00; var grandtotal = 0.00; var subtotal = parseFloat($("#Field148").val()); if($("#Field147").val() == "MN") { totaltax = subtotal * tax; grandtotal = round(totaltax + subtotal); $("#Field149").val(grandtotal); } else { grandtotal = round(subtotal); $("#Field149").val(grandtotal); } };
Thanks,
Chris