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

Prevent Form Fields from Auto Calculating the Next Field

New Here ,
Oct 02, 2023 Oct 02, 2023

Hello, I am a bit new to writing calculations in Adobe form fields. I am attempting to have individual fields calculate a given formula. Ex: (Given Number)*.0037. So that when a user fills the form with a whole number the field multiplies that number by .0037 to provide the calculated value we are required to display on our form.

I have tried multiple formulas. This following formula seems to work to make the calculation:

// Custom Validate script for text3
if (event.value) event.value = +event.value * .0037

 

However, the issue is that when I create the next form field (Text4) and enter a number into the field to be calculated the previous field (Text3) recalculates. Then if I highlight and change the number in (Text3), (Text4) recalculates.

How to I separate the fields so they do not calculate off each other? I want each field to be it's own calculation without influence from any other field on the form. Thank you for any help you can provide.

 

TOPICS
How to , JavaScript , PDF forms
1.2K
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 02, 2023 Oct 02, 2023

You state that the code is entered into a Validate, but the behavior you describe would only happen if the code was a calculation script is on the field where the data is entered? So that the field performs a calculation on itself? If true, then that is a really bad idea. The Calculate event is triggered every time any field on the form is changed. Make sure it is a custom Validate script and no calculations are taking place on any of the fields. 

 

Also, there is no need for the "if" statement in the code. 

 

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

View solution in original post

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 ,
Oct 02, 2023 Oct 02, 2023

You state that the code is entered into a Validate, but the behavior you describe would only happen if the code was a calculation script is on the field where the data is entered? So that the field performs a calculation on itself? If true, then that is a really bad idea. The Calculate event is triggered every time any field on the form is changed. Make sure it is a custom Validate script and no calculations are taking place on any of the fields. 

 

Also, there is no need for the "if" statement in the code. 

 

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
New Here ,
Oct 02, 2023 Oct 02, 2023

Thom,

 

Yes, you were spot on with what I was doing wrong. Your solution worked perfectly. Such a simple fix that I was struggling to resolve. I now have a much better understanding of how the form fields function. Thank you for your answer!!

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 ,
Oct 02, 2023 Oct 02, 2023
LATEST

You're welcome. Consider marking my answer as correct to close out the thread. 

 

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