Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Best function to count number of Drop Down Menu selections

PsychAssociatio
Level 2
Level 2

Hello,

I have a form that has a drop down menu in one section where the user can select various "Topics". The user can add as many of these drop down menus as they like, so it is unknown how many of them there will be on the form.

In another section of the form I have a table that summarizes the drop down menu selections. I need to know is what function I need to use to get the table to count the instances of each of the drop down menu selections.

For example, how many times the user selected "Apples", or "Oranges", or "Pears" from the drop-down menu.

Any help on which function for me to use would be appreciated.

Thank you

0 Replies
jasotastic81
Level 7
Level 7

Here's an example solution. I'm not certain how you set up the dropdown to repeat, so I'm presuming that there is a subform that contains the dropdown list each time it is repeated.


var apples = oranges = pears = 0;


var lists = xfa.resolveNodes("sfSomething[*].ddFruit"); //sfSomething is the repeated subform that contains the dropdown list ddFruit


for (i=0; i<lists.length; i++){


  apples = apples + (lists.item(i).rawValue == "apples"); //if the dropdown is "apples" +1 otherwise +0


  oranges = oranges + (lists.item(i).rawValue == "oranges");


  pears = pears + (lists.item(i).rawValue == "pears");


}


tfApples.rawValue = apples;


tfOranges.rawValue = oranges;


tfPears.rawValue = pears;


PsychAssociatio
Level 2
Level 2

Thank you for this information. I think I am just having trouble with my referencing and where I need to include this script on the form, as I have tried putting it in several places and nothing seems to happen.

Here is a link to the form with part of the script: https://drive.google.com/open?id=0BxnuJeLu0uyXWDZvQWRfWm82SHc

(I think once I have one or two items properly scripted I will be able to fix the rest)