5 Replies Latest reply on Jul 3, 2015 10:43 AM by dhoeky

# Help with a complex Acrobat Javascript Calculation

I'm trying to establish an if/then calculation for an Acrobat form and it's proving to be difficult.

The premise is that when a customer enters a quantity of 3 and have checked a box indicating a different packaging type, then a different price applies.

I'm trying to automate that in the totals field.

The qty fields are labels as: pre1, pre2. ... pre6

Check box is: pre_keg

Total qty is: text28

total cost is: pre_cost

reg price field is: pre_bottle_cost

different packaging field: pre_keg_cost

Any pointers on how to get this to work? Should it be done differently?

• ###### 1. Re: Help with a complex Acrobat Javascript Calculation

Got it to work with this code:

var nSubTotal = this.getField("Text28").value;

var bMember = this.getField("pre_keg").isBoxChecked(0);

if(( nSubTotal == 3,6,9 ) && bMember ) event.value = nSubTotal * 66.6666667;

else

if(!bMember) event.value = nSubTotal * 75;

• ###### 2. Re: Help with a complex Acrobat Javascript Calculation

The only issue is that the 'discouunted' price is still applying when the numbers are not 3,6, or 9

What statement will correct that?

• ###### 3. Re: Help with a complex Acrobat Javascript Calculation

There is no multiple or value compare, you need to individually test each value.

var nSubTotal = this.getField("Text28").value;

var bMember = this.getField("pre_keg").isBoxChecked(0);

if( ( nSubTotal == 3 || nSubTotal == 6 || nSubTotal == 9 ) && (bMember)  ) event.value = nSubTotal * 66.6666667;

else if(!bMember) event.value = nSubTotal * 75;

You also might want to round the event value since this is financial computation and mot finance amounts are not carried out to mils.

• ###### 4. Re: Help with a complex Acrobat Javascript Calculation

Thanks for the help, worked like a charm. The long event value is just to ensure that it adds up to \$200 for 3, \$400 for 6, etc.

• ###### 5. Re: Help with a complex Acrobat Javascript Calculation

But yes, it could be rounded.