1 Reply Latest reply on Mar 21, 2011 1:48 PM by gkaiseril

# Formula to divide field entry by a number

I have two form fields. One is set as a dollar amount and needs to be calculated by dividing the other form field entry by a specific number. I've tried multiple scripts that I found by searching all over the internet, but nothing works.

Does somebody know what the script should be, AND where can I go to learn about scripting?

• ###### 1. Re: Formula to divide field entry by a number

Did you change the field names to match your field names?

JavaScript does not generate a number result when dividing by zero. It creates either an 'NaN' string value or a string value for the number 'Infinity' or '-Infinity'. So unless you are placing your result in field with a format of "None", you need to control your code to avoid dividing by zero.

Since there is a possibility of dividing by zero, and simplified field notation can not handle conditional processing, the 'fi' statement, you need to write a custom calculation script.

For the field to hold the result of the calculation:

// establish variables for the field names for the dividend and divisor.

var sDividend = 'My Dividend Field Name';

var sDivisor = 'My Divisor Field Name';

// get the value of the divisor field

var nDivisor = this.getField(sDivisor).value;

// get the value of the dividend field

var nDividend = this.getField('sDividend').vlalue;

// do not change the code below this line

// clear the result field value

event.value = '';

// see if we have a non-zero divisor

if (nDivisor != 0) {

// we can now divide

event.value = nDividend / nDivisor;

} // end division calculation

The above assumes your are dividing the values of 2 fields.

There are tutorials at the Acrobat Users Community and Planet PDF. Ted Padova has written a number of books about Acrobat and Acrobat Forms.