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

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

Participant ,
Jan 19, 2018 Jan 19, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows
978
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

correct answers 1 Correct answer

LEGEND , Jan 19, 2018 Jan 19, 2018

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 getti

...
Translate
Community Expert ,
Jan 19, 2018 Jan 19, 2018

Check the calculation order.

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
Participant ,
Jan 19, 2018 Jan 19, 2018

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.

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 19, 2018 Jan 19, 2018

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.

A link to your form or a sample form with the same issue might be helpful.

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
Participant ,
Jan 19, 2018 Jan 19, 2018

Placing all of the calculations in one field was the answer with this.  I was trying to get too fancy with this.  THANK YOU!

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 19, 2018 Jan 19, 2018
LATEST

By having one calculation the issue of field calculation order comes down to 1 field.

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 19, 2018 Jan 19, 2018

You've described a classic calculation order issue, you need to check the calculation order dialog as gkiseril has described above.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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