Hi I think you should use Child table instead see Calculation in Child Table. But anyway, you can continue what you have started. I’m wondering why you have a for loop in your block
for(var i in sub_total) {
total = total + sub_total_1 + sub_total_2 + sub_total_3 + sub_total_4 + sub_total_5
}
I think it should be
total = frm.doc.sub_total_1 + frm.doc.sub_total_2 + frm.doc.sub_total_3 + frm.doc.sub_total_4 + frm.doc.sub_total_5