6 Replies Latest reply on Jan 19, 2018 4:57 PM by gkaiseril

Having trouble with result not changing if another number is added into the equation....

Hello Friends,

Thank you in advance for helping me learn Javascript!  If anyone has any advice on my current issue that would be fantastic.  I hope I can explain this so it's understandable.  Here are the scenarios:

Cell D = L16

Cell E = L17

Cell F = L18

Cell H = L20

Cell I = L21

Cell J = L22

Example:  If \$10,000 is entered in Cell D, \$250 is entered in Cell E, \$250 is entered in Cell F, I've written script that limits the entry into Cell F to 1.5%.  Cell J will automatically be \$10,000.  Here is my script which works!  The result is \$150.

var a = this.getField("L22").value;

if (event.value > a * .015)event.value=(event.value = a * .015);

else event.value;

if (event.value) event.value = util.printf("%.4f", event.value);

The issue happens when I enter an amount into Cell H (example \$5,000).  It is supposed to reduce Cell J.  So, the original amount of \$10,000 will reduce by \$5,000 with a new result of \$5,000.  Cell F should reduce down to \$75.00.  The problem is it doesn't reduce.  It stays at \$150.  If I go back to Cell F and enter \$250 again then it calculates down to \$75.  I am stumped how to write so it changes if a number is entered into Cell H and/or Cell I.

• 1. Re: Having trouble with result not changing if another number is added into the equation....

Check the calculation order.

• 2. Re: Having trouble with result not changing if another number is added into the equation....

That doesn't work.  Not sure how to remedy this.  The issue is the script I wrote for Cell F accepts whatever number I enter and it will change what actually shows in the cell based on the formula.  If I enter information into Cell H and/or Cell I this needs to change the calculation in Cell F.  In the example above if I enter 250 it changes to 150 and this is correct.  If I enter amounts in Cell H and/or Cell I then the number in Cell F should go down based on the 250 that was entered.  I'd to add to my validation script something that would make this happen.  If I go to Cell F and retype in the 250 then it calculates the new number based on what I enter in Cell H and Cell I.

• 3. Re: Having trouble with result not changing if another number is added into the equation....

Are you sure your field calculation order is correct. PDF forms are not Excel and form fields are not calculated left to right and then up to down. Calculation Order is not the same as tab order. It is a completely different setting from everything else. Also, one could place all the calculations in one field and perform the calculations and set the field values in the desired order You will find the "Set Field Calculation Order" under the "More" option for the "Prepare Forms" tool.

Are you getting any errors in the Acrobat JavaScript consloe?

Open it using the "<Ctrl> + J" key combination.