Skip to main content
aishwaryah32390957
Known Participant
June 7, 2018
Answered

Count number of drop-downs based on a selection

  • June 7, 2018
  • 1 reply
  • 1637 views

I have a form with several drop-downs fields. The values in the drop-down are "Please Select, F 1008, F 1009, F 1024, F 1173, F 1305,

F 1498, F 1573, Letter". For e.g, F 1008 is selected in a drop-down, the total value is 1. If F 1009 is selected in another drop-down. The total becomes 2. The count should run for all the values except for "Please Select". Is there a way to do this?

This topic has been closed for replies.
Correct answer try67

OK. In that case you can define this function as a doc-level script:

function countValues(v) {

    var total = 0;

    for (var i=1; i<=22; i++) {

        if (this.getField("ddref"+i).valueAsString==v) total++;

    }

    event.value = total;

}

And then as the custom calculation script of one of your text fields you can enter this code, for example:

countValues("F 1008");

1 reply

try67
Community Expert
June 7, 2018

Yes, this can be done using a script.

What are the names of the drop-down fields?

aishwaryah32390957
Known Participant
June 7, 2018

Thank you for helping.

The names are: "ddref1","ddref2" ... to "ddref22"

aishwaryah32390957
Known Participant
June 7, 2018

OK. In that case you can define this function as a doc-level script:

function countValues(v) {

    var total = 0;

    for (var i=1; i<=22; i++) {

        if (this.getField("ddref"+i).valueAsString==v) total++;

    }

    event.value = total;

}

And then as the custom calculation script of one of your text fields you can enter this code, for example:

countValues("F 1008");


Should i be adding as the document script?

Because i have other calculations in the form.