Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
14

Calculations Multiplying When I Enter A Value Into A Different Field

Community Beginner ,
Nov 02, 2023 Nov 02, 2023

So, I've been working on this form for call notation for our company. Most of fields are just entry fields for customer information and drop-downs for certain types of customers/calls. The issue I'm running into is on the bottom, where I am trying to calculate how much a transport would cost based on the options chosen in earlier fields. I can't even get through the mileage part yet, let alone the total estimate cost that would be using conditionals. The problem I'm having is that I put the code into the "Custom Calculation Script" under the "Calculate" tab. I am doing this is multiple fields, but changing the field name and calculation each time, but when I go to test the calculations. The first field I try works great, then I go to the second field to calculate a second number and calculates the value again, this time by the newer value. So, for example, I've got a "Mileage" field that multiplies the field entry by 3.25 (aka Cost Per Mile). I have used three different types of code for this and all have the same issue:

 

event.value = event.target.value * 3.25;

event.value = getField("Mileage").value * 3.25;

event.value = this.getField("Mileage").value * 3.25;

 

Say I enter the value 19 into this field. It will calculate it to 61.75, which is correct. But then, I will move on to another field and enter a value. As soon as I hit Enter or Tab, it will calculate that second field, but will also calculate this first Mileage field again. Resulting in an output of 200.69 (I have a number format on both fields so that it rounds to the hundreth place instead of having a long decimal).

 

I'm super confused with this and it's getting frustrating because I cannot move onto the even more complicated conditional calculations and whenever I research this issue, all the solutions are telling me to do exactly this code I have already tried.

 

Any help is greatly appreciated! Note that I am using Adobe Acrobat Pro and am into the "Prepare a form" editor.

TOPICS
General troubleshooting , JavaScript , PDF forms
2.9K
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 ,
Nov 02, 2023 Nov 02, 2023

You can't do this:

 

event.value = event.target.value * 3.25;

 

Calculations are triggered anytime any field is changed. So this line used as a calculation just continually recalculates itself.

 

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
Community Beginner ,
Nov 02, 2023 Nov 02, 2023

Oh, okay. How about event.value = getField("Mileage").value * 3.25; and event.value = this.getField("Mileage").value * 3.25;?

Do they always go into a neverending calculation when you use the same field the code is in in that calculation, or is there a different code that I can use to get around it becoming cyclical.

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

This code is fine, unless you're applying it to the Mileage 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 Beginner ,
Nov 02, 2023 Nov 02, 2023

Hmmm... The Mileage field is what I am trying to adjust. Should I make another field to do the calculations instead? I need the same field that I am inputing to also output the answer of the calculation.

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

You need to better explain what you're trying to achieve. We could then help you with the code/formula to do it.

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

Why make things complicated when you can make them simple?

 

Capture_2311021744.png


Acrobate du PDF, InDesigner et Photoshopographe
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 Beginner ,
Nov 02, 2023 Nov 02, 2023

I have tried this and it also does the same thing. I think the main issue is that I am trying to calculate with the same field that the calculation is in. I've done this in excel and using programming languages such as Java before and it worked just fine, but I suppose I have been spoiled with the ability to tell it how many times I want the code ran instead of it re-running ever time any field is being changed.

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