Copy link to clipboard
Copied
Hi! I don't have any experience with script, but I think that I need to create a custom calculation script in my Adobe Acrobat form.
I have created a budget form and simply want to be able to enter expenses and have them automatically add up the running total. I'm trying to figure out a way to code this in the calculation area easily, without needing to write new code for each box.
So, for example, the form looks like this:
Date Description Category Amount Balance
4/23 Chipotle Food $25 $25
4/25 Starbucks Food $10 $35
4/27 Target Supplies $100 $135
I want the form to be able to automatically calculate that the balance is 35 when I add in the 10 for Starbucks, then 135 when I enter 100 for Target, etc. From looking it up in the past, I used the following for some similar calculations:
// Obtain the value from the first field
var v1 = getField("balance1").value;
// Obtain the value from the second field
var v2 = getField("amount2").value;
// Set this field value equal to the sum
event.value = v1 + v2;
When balance1 is the $25 and amount2 is the $10.
Is there a way I can change this formula to be able to use it for every balance field without needing to edit the formula in each one separately?
Thank you for your assistance!!
kristy
Copy link to clipboard
Copied
OK, then this is the doc-level script you can use (insert it under Tools - JavaScripts - Document JavaScripts):
function calcBalance() {
var rowNumber = Number(event.target.name.replace("balance", ""));
var amount = Number(this.getField("amount"+rowNumber).valueAsString);
if (amount==0) event.value = "";
else {
var prevBalance = 0;
if (rowNumber!=1) prevBalance = Number(this.getField("balance"+(rowNumber-1)).valueAsString);
event.value = amount+prevBalance;
}
}
And then the custom calculation script of each "balance" field is simply:
calcBalance();
Copy link to clipboard
Copied
I need help. I need to know the code to calculate the Freight=Labels &Tags + Valves & Components (0.07)
Copy link to clipboard
Copied
Do you mean: (Labels &Tags + Valves & Components) * (0.07) ?
Copy link to clipboard
Copied
Yes, but I need that total to go to the fright column. If that makes sense.
Copy link to clipboard
Copied
You can use this code as that field's custom calculation script, then, just make sure the field names are spelled EXACTLY as they are in your file:
event.value = (Number(this.getField("Labels &Tags").valueAsString) + Number(this.getField("Valves & Components").valueAsString)) * 0.07;
Copy link to clipboard
Copied
Excalent first reply, so you could say this is a probllem of scope_
Copy link to clipboard
Copied
Looking for some help. I am trying to find a calculation to put into Adobe, where I multiple the rank*weight of each row, then the priority score is the sum of it all.
Bonus: I am also looking to see if I can add a field under the Number Priority Score that states the word equivalent (So if the score is under 15, it will say "Good," between 15 and 22 "Excellent",and 23 and above "Outstanding"