How to divide two fields value and store the output in the 3 field

Hi @Stellar,

Please apply and check it.

When you save it then value automatically set in field.

frappe.ui.form.on('Sales Invoice',  {
    before_save: function(frm) {
        $.each(frm.doc.items,  function(i,  d) {
            d.total_cartons = d.stock_qty / d.units_in_carton;
            frm.refresh_field('items');
        });
    } 
});