Custom script how to update child table row

I’m trying to automatically calculate the total sum in an invoice per row for all items. The problem is that I cannot get the user interface to update the price. I’m trying the following:

frappe.ui.form.on('Invoice Product', "item_code",
	function (frm, cdt, cdn) {
		var item = locals[cdt][cdn];
               alert( //Default value shown
               //Do magic = xyz //This change is not visible on the ui

How do I refresh the change of the total value to the ui?
Also is there a way to run this handler on change of any of the child table fields instead of just copy pasting this code to each of those fields?