I'm writing a script like the example shown in the demo where All of the "Total" values (Including the "Grand Total") are Automatically Calculated using the calc () method. at this link:
But I have some fields in which to apply the equation qty * price, and others where I want to do other operations .. you can tell me how? thank you very much
i try with this, but it is a very stupid code .. and the grandTotal .. not sum the two different fields:
function recalc() {
$("[id^=total_item]").calc("qty * price", {
qty: $("input[name^=qty_item_]"),
price: $("[id^=price_item_]")
}, function (s){
// return the number as a dollar amount
return "$" + s.toFixed(2);
}, function ($this){
// sum the total of the $("[id^=total_item]") selector
var sum = $this.sum();
$("#grandTotal").text(
// round the results to 2 digits
"$" + sum.toFixed(2)
);
});
$("[id^=total_otheritem]").calc("qty1 / price1", {
qty1: $("input[name^=qty_other_]"),
price1: $("[id^=price_other_]")
}, function (s){
// return the number as a dollar amount
return "$" + s.toFixed(2);
}, function ($this){
var sum = $this.sum();
$("#grandTotal").text(
// round the results to 2 digits
"$" + sum.toFixed(2)
);
});
}