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

Calculate the total of dropdown value selected

New Here ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

Hi

 

I am creating a inspection report, with a list of inspection items. At the side of each items, I have a dropdown list of Pass, to be rectified, N.A. At the end of the report, I want to show the total number of "Pass" selected, "to be rectified" and "N.A". I only need to know how many passes are there, how many "to be rectified" are selected and so on. How can I do that?

TOPICS
How to , JavaScript , PDF forms

Views

113

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 , Jun 26, 2024 Jun 26, 2024

OK, then you can use this code as the custom calculation script of the field that counts the number of "Pass" selections:

 

var total = 0;
var fields = this.getField("Dropdown3").getArray();
for (var i in fields) {
	if (fields[i].valueAsString=="Pass") total++;
}
event.value = total;

Simply adjust the string in the fourth line to re-use it for the other values.

Votes

Translate

Translate
Community Expert ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

What are the names of those fields?

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 ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

Screenshot 2024-06-26 at 6.40.47 PM.png

 

Pass, Rectified, to be rectified, N.A. In the dropdown list also these 4 items.

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
Community Expert ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

OK, then you can use this code as the custom calculation script of the field that counts the number of "Pass" selections:

 

var total = 0;
var fields = this.getField("Dropdown3").getArray();
for (var i in fields) {
	if (fields[i].valueAsString=="Pass") total++;
}
event.value = total;

Simply adjust the string in the fourth line to re-use it for the other values.

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 ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

It works now. Thank you so much.

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 ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Hi @try67 , does the script work on iOS app? It doesn't seem to work when I use it on my mobile app.

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

LATEST

Only some basic JavaScript functions works on mobile devices, so this script won't work, you can try "PDF Expert" app by Readdle for iOS it has more support for JavaScript.

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