Copy link to clipboard
Copied
I want to create a calculation so if a customer checks all six boxes it gives them a discount.
Box 1: $50
Box 2: $50
Box 3: $50
Box 4: $50
Box 5: $50
Box 6: $50
If all six boxes are checked then: Box 1:Box 6 - $50 = $250
If all boxes are not checked then regular calculation applies
Thanks in advance!!!
Copy link to clipboard
Copied
You can use this code as your custom calculation script for the total field:
var total = 0;
for (var i=1; i<=6; i++)
if (this.getField("Box "+i).value!="Off") total+=50;
if (total==300) total-=50;
event.value = total;
Copy link to clipboard
Copied
Thank you! This worked as well!
Copy link to clipboard
Copied
There are 3 options for calculating field values. The first two, selecting field and simplified field notation have no provision for controlling the lines executed by JavaScript. This is only available using the Custom JavaScript option. This will require identifying each field's object and then applying logic to tell if all six items have been selected. You will have to check if a field is checked or not by testing the value of the field. A value of "Off" indicates no selection has been made. One could test each check box and count or sum as needed or place the value of each field into an element in an array and then filtering out the "Off" elements. One can then sum the elements of the array and if the number of elements in the array is 6 then apply the discount.
Copy link to clipboard
Copied
Thank you very much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now