These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Drop Down value counts- Adobe Acrobat Pro

katmetz
Registered: Nov 29 2011
Posts: 7
Answered

I am trying to use Adobe Acrobat Pro to create some forms to be used on my IPad. All my forms that were previously created using LiveCycle using FormCalc script do not work. I was told that I have to use Java Script in Adobe Acrobat Pro to make it work.
 
I am creating an Expense report that has categories of expenses. Dependent on the selection of the form filler in each drop down, I need to count the values for a total amount at the bottom. For example, I have 25 expense rows to fill in by the user. Each line includes a date, text description, amount, and category. The category is the drop down list entry.
 
I need to know how to do the Java Script to take the user selected drop down items and total the amount of money spent for each category at the bottom. I know absolutely nothing about Java Script.
 
If this makes any sense.. can someone help!
 
Thanks!

K. Harrison

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
What PDF viewer are you using on your iPad? I believe the only one that has a chance of working with your form is Readdle's PDF Expert.
katmetz
Registered: Nov 29 2011
Posts: 7
Yes! I am using PDF Expert by Readdle. They are the one that provided the information about using forms only created in Adobe Pro. It does not support LiveCycles Script.

K. Harrison

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
That's good. I don't really understand how the form is set up, so it's hard to make specific suggestions. How many different categories are there and exactly how have you set up the combo boxes (items, export values, field names, etc.) Also, for the summary at the bottom, do you have separate fields for the totals for each category?
katmetz
Registered: Nov 29 2011
Posts: 7
The form is set up to look like a chart. The chart has 25 rows with 4 columns with headings Date, Description, Amount, and Category. The Category column is set up using a combo box that has 29 Categories listed. (example of these categories are Travel Expense, Car Rental, Fuel Expense, Supplies, Meals, and Other.. etc.)

I have 25 of these Category combo boxes all named CategoryList1. so it numbers them #1,2,3 etc..
To the left of the Category column is the Amount column. This column is TextFields all named Amount1. so it numbers them #1,2,3. etc.. This is formatted to a number.

On a second page, I have a summary of each category type separated for the calculated totals. This is set up as a TextField Formatted to a number. Each box is named something different. (ex. nCount1, nCount2, nCount3, nCount4, nCount5, etc..)

I also created under the properties of the form, Custom values setting each total with a value of 0 (ex. nCount1 = 0, nCount2= 0, nCount 3=0 etc.. ) I don't know if this is correct, but I carried it over from my use with LiveCycle Designer.


K. Harrison

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
I just found a bug in PDF Expert 3.1.2 that seems to prevent automatic calculations unless some other code is first executed, so I'll include a workaround, but let's get to that later.

Begin by creating the following document-level JavaScript (Advanced -- Document Processing -- Document JavaScripts):

  1. function sumCategoryAmounts(category) {
  2.  
  3. // Initialize variables
  4. var sum = 0;
  5. var cat;
  6.  
  7. // Sum the amounts that match the category
  8. for (var i = 1; i < 26; i += 1) {
  9. cat = getField("CategoryList" + i).value;
  10. sum += cat === category ? +getField("Amount" + i).value : 0;
  11. }
  12.  
  13. // Set the value of the field that called this function
  14. event.value = sum;
  15. }
And then call this function in each of the nCount fields like this:

// Custom calculate script for nCount1 field
sumCategoryAmounts("First category label")

Where "First category label" is the first item in your list. For nCount2, use:

// Custom calculate script for nCount2 field
sumCategoryAmounts("Second category label")

and so on for all of the nCount fields.

To bypass the bug, first test the form in PDF Expert to see if you need to by entering values in the amount fields, selecting a category from the combo boxes, and seeing if the fields automatically calculate. If not, go back to the form and edit it by adding a button somewhere, give it a label of something like "Start", and add the following code to the Mouse Up event:

var bogus;

Try the form again to see if it calculates. If not, click the button and try again.

I'm going to look into the bug a bit more and try to come up with a less intrusive workaround.