Summing up Line item totals and copy to master table total

Use this sample to sum up line item totals and copy the value to the totals field on the master table.Place the code at: Client Scripts->Table Specific->List Page-> Startup Script

function calculateSum() {
	var sum = 0;
	//iterate through each textboxes and add the values
	$("[data-field=x_line_total]").each(function () {// line total field in details field
		//add only if the value is number
		if (!isNaN(this.value) && this.value.length != 0) {
			sum += parseFloat(this.value);
		}
	});
	$("#x_inv_amount").val(sum.toFixed(2));// id of field in master table
}
<?php if(CurrentPageID() == "add"){?>
$("#tbl_detail_tablegrid").on("change", "[data-field=x_field_x]", function () {//activate fxn on change on specific field in detail table
	 calculateSum();
});
<?php }?>

I have copied your provided code and paste it exactly where you advised.
But nothing is changing.
Will it sumup the total before saving or after saving ?
and also can u explain this portion [data-field=x_field_x] ?function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(“[data-field=x1_orderdetails_sitotal]”).each(function () {// line total field in details field
//add only if the value is number
if (!isNaN(this.value) && this.value.length != 0) {
sum += parseFloat(this.value);
}
});
$(“#x_orders_sigtotal”).val(sum.toFixed(2));// id of field in master table
}

<?php if(CurrentPageID() == "add"){?>

$(“#tbl_detail_tablegrid”).on(“change”, “[data-field=x_field_x]”, function () {//activate fxn on change on specific field in detail table
calculateSum();
});

<?php }?>

It won’t work in v2021. You may read the reason for this post: https://discourse.hkvstore.com/t/auto-update-column-in-master-table-before-save-record/3739/2