Math Operation on fields

I just try copy and paste the code from this link https://discuss.frappe.io/t/trigger-recalculation-after-change-in-customfield/7394/15?u=iqbalzahir

here is the code:

frappe.ui.form.on("Employee Receipt", "payment", function(frm) {
       cur_frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay * frm.doc.payment));
       frappe.msgprint(frm.doc.payment);
});
frappe.ui.form.on("Employee Receipt", "total_need_to_pay", function(frm) {
       cur_frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay * frm.doc.payment));
       frappe.msgprint(frm.doc.total_need_to_pay);
});
frappe.ui.form.on("Employee Receipt", "balance_need_to_pay", function(frm) {
       cur_frm.set_value("balance_need_to_pay", (frm.doc.total_need_to_pay * frm.doc.payment));
       frappe.msgprint(frm.doc.balance_need_to_pay);
});

It worked when i edit the current employee receipt. but when i want to create the new employee receipt, it slow down the browser.
here is the pic:


it just stucked!