php - javascript calculate 10% discount on sub total -
how implement calculating 10% discount base on sub total in js?. here code.
<!-- sub total --> function calculategrandtotal() { var grandtotal = 0; $('table tbody tr td:nth-child(4) input').each(function (index) { grandtotal += parseint($(this).val()); }); $('#sub_total').val(grandtotal); }
it this:
function calculategrandtotal() { var grandtotal = 0; $('table tbody tr td:nth-child(4) input').each(function (index) { grandtotal += parseint($(this).val()); }); $('#sub_total').val(grandtotal); $('#discount').val(calculatediscount(grandtotal)); } //separate function calculate discount function calculatediscount(amt){ if(!nan(amt)){ return amt*0.1;//10% disc }else return 0; }
Comments
Post a Comment