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

Count number of drop-downs based on a selection

Community Beginner ,
Jun 07, 2018 Jun 07, 2018

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?

TOPICS
PDF forms
1.5K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 07, 2018 Jun 07, 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");

View solution in original post

Translate
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 07, 2018 Jun 07, 2018

Yes, this can be done using a script.

What are the names of the drop-down fields?

Translate
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 Beginner ,
Jun 07, 2018 Jun 07, 2018

Thank you for helping.

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

Translate
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 07, 2018 Jun 07, 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");

Translate
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 Beginner ,
Jun 07, 2018 Jun 07, 2018

Should i be adding as the document script?

Because i have other calculations in the form.

Translate
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 07, 2018 Jun 07, 2018

You can create multiple doc-level scripts. There's no conflict there, unless you use the same function names.

Translate
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 Beginner ,
Jun 07, 2018 Jun 07, 2018

I'll try it and let you know if it works.. by the way.. i have other dropdown in the same form.. the drop down has values like "Please select", "Yes", "No".. The fields needs to count for the number of yes only..

The dropdowns' names are "ddcard1", "ddcard2" .... to "ddcard22".

Translate
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 07, 2018 Jun 07, 2018

You can easily convert the code I provided to do it... Just change the function name and the base field-name.

Translate
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 Beginner ,
Jun 07, 2018 Jun 07, 2018
LATEST

Thank you for helping.

It's working correctly.

Translate
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