Skip to main content
Participant
December 30, 2021
Question

Count the number of dropdown items selected

  • December 30, 2021
  • 1 reply
  • 1019 views

I am creating a fillable form which includes a dropdown list. The two options are "Vacant" or "Occupied". I want to be able to count the number of "Vacant" entries in a separate field. The dropdowns are named "dropdown.10" through "dropdown.31". I have tried scripts from a number of different answers to similar questions with no success. I attached two images as a reference and I can provide more information if needed. Thanks.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
December 30, 2021

You can use this code as the custom calculation script of a text field to count the number of times "Vacant" is selected:

 

var total = 0;
for (var i=10; i<=31; i++) {
	if (this.getField("dropdown."+i).valueAsString=="Vacant") total++;
}
event.value = total;
Participant
December 30, 2021

Try,

 

That script did not work for me. Could there be something wrong with my doc?

try67
Community Expert
Community Expert
December 30, 2021

I can't say for sure without seeing it...