How to do calculation in child table rows

frappe.ui.form.on("Gatepass Detail", {
    quantity: function(frm, cdt, cdn) {
        calculateTotalWeight(frm, cdt, cdn);
    },
    weight: function(frm, cdt, cdn) {
        calculateTotalWeight(frm, cdt, cdn);
    }
});

function calculateTotalWeight(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
    var totalValue = d.quantity * d.weight;
    frappe.model.set_value(cdt, cdn, 'total_weight', totalValue);
    // Optionally refresh the field if necessary
    // frm.refresh_field('total_weight');
}