• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Acrobat PDF count dropdown choices

New Here ,
Apr 05, 2018 Apr 05, 2018

Copy link to clipboard

Copied

I've created a fillable PDF form in Acrobat where each question has two letter choices which are listed these in a dropdown box (i.e. Question 1 can either be A or B, Question 2 can either be C or D). At the end of the document, I need 4 text boxes that count the number of A's, B's, C's and D's have been chosen in the dropdown boxes.

I'm a complete beginner when it comes to Javascript, so can anyone please advise a code I can input to achieve this?

Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

772

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 05, 2018 Apr 05, 2018

Only part of the solution is JavaScript, the other part is in the field naming. The fields need to be named so that they are easy to access in a script. For your case, the best solution is to use "dot" notation to group the fields. This only works for fields that are of the same type.

For example, the dropdown fields are gouped with "Section1" as the prefix and each individual dropdown is Q1 thru Q4.

Then the full field names (as entered in the Field Properties dialog) are:  "Section1.Q1", "Sectio

...

Votes

Translate

Translate
Community Expert ,
Apr 05, 2018 Apr 05, 2018

Copy link to clipboard

Copied

Only part of the solution is JavaScript, the other part is in the field naming. The fields need to be named so that they are easy to access in a script. For your case, the best solution is to use "dot" notation to group the fields. This only works for fields that are of the same type.

For example, the dropdown fields are gouped with "Section1" as the prefix and each individual dropdown is Q1 thru Q4.

Then the full field names (as entered in the Field Properties dialog) are:  "Section1.Q1", "Section1.Q2", "Section1.Q3", "Section1.Q4",

This calculation script will count the number of selected A's. i.e., this code goes into the calculation script for the A text box

var nSum = 0;

this.getField("Section1").getArray().forEach(function(a){if(a.value=="A") nSum++;});

event.value = nSum;

This code works regardless of the number of questions. The only thing that matters is that all the questions are grouped in "Section1"

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
New Here ,
Apr 05, 2018 Apr 05, 2018

Copy link to clipboard

Copied

LATEST

Thank you for such a quick response, this works perfectly!

Votes

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
community guidelines