How to sum data from a child table in real time?

I’m trying to sum totals for the rows in a child table, but I want to get this calculation to run in real time and summed up in the parent field.

total_references:function(frm, cdt, cdn){
	var d = locals[cdt][cdn];
	var total = 0;
	frm.doc.references.forEach(function(d) { total += d.total_amount; });
	frm.set_value("total_references", total);
	refresh_field("total_references");
},

See here is example matches your post Hope this helps

I was following the example but it does not update the result in real time.

@Deybi_Tabora_Paz You have to change last line to This:

frm.refresh_field(“total_references”);

Ready, but for some reason when I add a record to the secondary table, the function that makes the calculation does not run.