Skip to main content
Participant
June 26, 2024
Answered

Calculate the total of dropdown value selected

  • June 26, 2024
  • 1 reply
  • 907 views

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?

This topic has been closed for replies.
Correct answer Nesa Nurani

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


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.

1 reply

try67
Community Expert
Community Expert
June 26, 2024

What are the names of those fields?

MINT TEEAuthor
Participant
June 26, 2024

 

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

try67
Community Expert
Community Expert
June 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.