Hi, i’m using PHPMaker 2021.0.15, i want to sum sub total fields in detail table, but i got error “Uncaught ReferenceError: CalculateTotal is not defined”.Here’s my code:
- In edit Tag, client side events
{ // keys = event types, values = handler functions
“keyup”: function(e) {
var $row = $(this).fields();
var total_amount = $row[“harga_detail”].toNumber() * $row[“jumlah_detail”].toNumber();
//update total amount for this row
if((total_amount > 0) || (total_amount < 0))
{$row[“sub_total”].value(total_amount);}
else
{$row[“sub_total”].value(“0”);}
CalculateTotal();
}
}
- Client Script → Add page
function CalculateTotal(){
var net_amount = 0;
var all_amounts = $(‘[data-field=“x_sub_total”]’);
for(var i = 0;i < all_amounts.length;i++){
var the_amount = 0;
//ensure that its the input controll of interest
if(all_amounts[i].className == “form-control”){
the_amount = all_amounts[i].value;
if(!(the_amount > 0)){the_amount = 0;}
net_amount += parseFloat(the_amount);
}
}
//show the net amount anywhere for now am putting in console log
console.log(net_amount);
}