Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
This code is fine, unless you're applying it to the Mileage field...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You need to better explain what you're trying to achieve. We could then help you with the code/formula to do it.
Copy link to clipboard
Copied
Why make things complicated when you can make them simple?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now