populate sum of 4 number fiels in other field dynamically

dixitreddy
Tera Contributor

Hi,

i have a requirement that in the for there r 4 fields A,B,C,D currency fields or number fiels when i enter this values in the form it should do sum of all these a+b+c+d and populate in other field called E before saving form it self it should calculate and populate

9 REPLIES 9

Community Alums
Not applicable

Hi @dixitreddy ,

You have 4 fields and if you create OnLoad client script it works on only one field. For example you created onLoad client script on Field A and if you didn't change the value of field A the script will not work. 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Community Alums
Not applicable

Hi @dixitreddy ,

I tried with OnSubmit client script it works for me please check below code 

function onSubmit() {
    //Type appropriate comment here, and begin script below

	

    var fieldA = g_form.getValue('u_a');
    var fieldB = g_form.getValue('u_b');
    var fieldC = g_form.getValue('u_c');
    var fieldD = g_form.getValue('u_d');
	alert('A = ' + fieldA + " B = " + fieldB + " C = " + fieldC + " D "+ fieldD);

    var e = parseInt(fieldA) + parseInt(fieldB) + parseInt(fieldC) + parseInt(fieldD);
	alert("E - " + e);
    g_form.setValue('u_e', e);


}

Result 

SarthakKashyap_0-1714640032522.png

Total in E

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

will it work on onchange? before saving form i need sum of values to populate

Community Alums
Not applicable

Hi @dixitreddy ,

This is will on OnChange client script for example if you apply OnChange Client script on field D, so each and everytime you need to change the value of field D to calculate the sum of all 4 fields 

 

Please mark my answer correct and helpful if this work for you

 

Thanks and Regards 

Sarthak

on change will work only in one field at a time i want to enter 4 values and it should do sum then the on change wont work here