1 Reply Latest reply on May 28, 2009 9:15 AM by gkaiseril

Calculation with conditional clauses

Hi There,

I have a rather complicated calculation in an Acrobat form that can't get away without writing javascript. The trouble is I don't know how to write javascript!

So if there is someone here that's kind enough help me out, I would certainly appreciate it!

Here are the conditions:

SUM is a summation of many other fields which is given here, TOTAL is the value we need to calculate.

If SUM is less than 1500, TOTAL should be SUM

If SUM is between 1500 and 1875, TOTAL should be 1500.

If SUM is between 1875 and 2500, TOTAL should be SUM * 0.8

If SUM is between 2500 and 3400, TOTAL should be 2500

If SUM is above 3400, TOTAL should be SUM * 0.75

I guess this requires javascript on certain fields and also on the document level, so please let me know where to put them!

Thanks a million,

Mark

• 1. Re: Calculation with conditional clauses

For the 'TOTAL' field you can use the following custom calculation script:

var fSum = this.getField('SUM').value; // get the value of the field named 'SUM'

switch(true) {

case (fSum < 1500) :

// sum less than 1500

this.getField('TOTAL').value = fSum; // total is sum

break; // exit test

case (fSum < 1875):

// sum < 1875 - we have already taken care of  < 1500

this.getField('TOTAL').value = 1500; // total is 1500

break; // exit test

case (fSum < 2500):

// sum < 2500 - we have already taken care of < 1875

this.getField('TOTAL').value = fSum * 0.8; // total is 80% of sum

break; // exit test

case (fSum < 3400):

// sum < 3400 - we have already taken care of , 2500

this.getField('TOTAL').value = 2500; // total is 2500

break; // exit test

default:

// only 3400 and above left

this.getField('TOTAL').value = fSum * 0.75; // total is 75% of sum

break; // exit test

} // end all test