Skip to main content
Participant
Jan 12, 2016 8:10 PM UTC
Question

Calculation in PDF Form

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!!! 

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Inspiring
Jan 12, 2016 9:39 PM UTC

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.

Translate
Participant
Jan 13, 2016 8:19 PM UTC

Thank you very much!  

Translate
try67
Community Expert
Community Expert
Jan 12, 2016 9:35 PM UTC

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;

Translate
Participant
Jan 13, 2016 8:20 PM UTC

Thank you!  This worked as well! 

Translate