Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculation in PDF Form

New Here ,
Jan 12, 2016 Jan 12, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows
465
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2016 Jan 12, 2016

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 13, 2016 Jan 13, 2016
LATEST

Thank you!  This worked as well! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2016 Jan 12, 2016

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 13, 2016 Jan 13, 2016

Thank you very much!  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines