I’ve the following HTML code: https://jsfiddle.net/tnLad51z/
It’s a simple table with:
- 1 input for the price without tax
- 2 inputs for the taxes
- 1 input for the final price with tax
All the variables looks working well but do I use the ideal way to do these type of calculations ?
function updatePriceWithTaxe() { var total_taxes = 0; var total_without_taxes = Number($ ('input[name="RAT_Price"]').val()); $ ('input[name="STX_Amount[]"]').each(function() { total_taxes += Number($ (this).val()); }); // Calculs total_taxes = total_without_taxes * total_taxes / 100; total_with_taxes = total_without_taxes + total_taxes; // Output console.log(total_with_taxes.toFixed(2)); $ ('input[name="RAT_PriceTaxed"]').prop('readonly', false).val(total_with_taxes.toFixed(2)).prop('readonly', true); }
Should I need to add some error handling around non-numbers in the tax area?
Actually, a ‘NaN’ shows up in the ‘total’ if I don’t put some number?
How can I make this?
Thanks.