Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Apply Script to multiple fields

Avatar

Former Community Member
I have a form with multiple fields that will contribute to a total. Is there a way to have script apply to multiple fields that will auto update the totals, instead of scripting a separate exit event for each field.



Thank you
2 Replies

Avatar

Former Community Member
Create a Script Object. In that object, you can have a function like this:

function addMyFields() // add values in the fields

{

var number1 = field1.rawValue;

var number2 = field2.rawValue; // and so on



var sumOp = number1 + number2; // + number3 + .... and so on



totalField.rawValue = sumOp; // display sum in total field

}



Paste the following code in the exit event of each field:

ScriptObjectName.addMyFields();



Let me know if it works for you.

Avatar

Former Community Member
Or put your code on the Calculate event and as each field is changed the Total calculate event wil fire because there is a dependency between each field mentioned in the calc.