Calculate average from child table

I want calculate average of work completed. This child table is read only.
i want to add all ‘Work Completed’ score and fine average and display in ‘Total Work Plan Complete(100%)’ before save.

i used below code:

cur_frm.cscript.total_work_plan = function(doc,cdt,cdn){
var total3 = 0;
var row_length = cur_frm.doc.plan_template.length || 0;
$.each(cur_frm.doc.plan_template || [], function(i, row){
total3 += row.work_completed/row_length;
cur_frm.set_value(“total_work_plan”, total3);
//doc.total_work_plan = flt(total3);


sorry for repeated question