Highlighted

Need help with calculation script

New Here ,
Jul 21, 2020

Copy link to clipboard

Copied

I have a form where users will enter data.  The first field (Category) is a dropdown list of 11 items (A-K) - they must choose one of them.  Next there is a field where they will enter a number (Amount_Earned).  This is repeated 12 times, so users can enter more than one value for each list item if desired. I want to create a script to show the sum of the Amount_Earned fields (specifically Amount_Earned.0-Amount_earned.11) where A was selected for Category (specifically Category.0-Category.11).  I will then create similar fields to sum each based on a different selection from the dropdown list, so I will end up with 11 fields showing the sums of values where each A-K were selected. Attached is a simplified version of the form - only the fields needed for the calculations are included.  I have a lot of experience with forms and simple form calculations, but I am a newbie at scripting and can't figure it out.  Any help appreciated!

Topics

PDF forms

Views

97

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Need help with calculation script

New Here ,
Jul 21, 2020

Copy link to clipboard

Copied

I have a form where users will enter data.  The first field (Category) is a dropdown list of 11 items (A-K) - they must choose one of them.  Next there is a field where they will enter a number (Amount_Earned).  This is repeated 12 times, so users can enter more than one value for each list item if desired. I want to create a script to show the sum of the Amount_Earned fields (specifically Amount_Earned.0-Amount_earned.11) where A was selected for Category (specifically Category.0-Category.11).  I will then create similar fields to sum each based on a different selection from the dropdown list, so I will end up with 11 fields showing the sums of values where each A-K were selected. Attached is a simplified version of the form - only the fields needed for the calculations are included.  I have a lot of experience with forms and simple form calculations, but I am a newbie at scripting and can't figure it out.  Any help appreciated!

Topics

PDF forms

Views

98

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

I can't believe no one has done this before.  please help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Aug 02, 2020

Copy link to clipboard

Copied

To test values you must use ==, not only =

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Participant ,
Aug 02, 2020

Copy link to clipboard

Copied

Hi, first of all let me just say I don't know how to code i'm just begginer but I think I found workaround
for your problem ( I hope it is what you were looking for) and i'm pretty sure it can be done much easier
from someone who knows coding.
Ok here we go:
This is just for Selection "A" for rest selections just modify code.

1. Create 12 Text Fields ( you can make them hidden)
I named them A0-A11 (you can name them something else but then don't forget to modify code if you change their names)

2. In each text field "custom Calculation Script" enter this code but for each field modify field names in each code ( just change number
from 0 to 1,2...etc).

var a = this.getField("Amount_Earned.0").value;
var b = this.getField("Category.0").value;
var c = this.getField("A0");
if (b == "A"){
c.value = a;
}
else event.value = "";

3.Go to field "Requested Category A" calculation-> and check "value is the" -> pick, and pick fields A0-A11.
Repeat for selections B-K.
here  is your file with added codes so you can check if thats what you wanted.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
swiesbro LATEST
New Here ,
Aug 03, 2020

Copy link to clipboard

Copied

Thanks very much for the reply.  It seems like kind of a brute force approach, but it does actually work.  I'm sure there is a more elegant way to get Acrobat to do the same calculations 12 times rather than create 12 fields, but for now it works!

 

Thanks again - am not marking this correct just yet in case some scripting pro wants to provide the more elegant answer!!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF