How to count selected options from a drop-down field?

  • Impacct
    Asked on June 20, 2017 at 7:24 PM

    I am putting together a form where I have assigned 2 calculation options to a dropdown. I want to add up each value separately from all dropdowns together, but I'm not sure how to put this into a form calculation.

    For example, each dropdown has options equal to 1 and options equal to 2.

    I want to add up all the options equal to 1 in one cell (A) and add up all the options equal to 2 in another cell (B).

    So for example, if 5 dropdowns are selected and 2 of them have options equal to 1 and 3 have options equal to 2, cell A with show 2, and cell B will show 3.

    Please let me know if it is possible to do this and how to go about it.


    Thanks!

     

    -Ilana 

  • Kevin Support Team Lead
    Replied on June 20, 2017 at 9:54 PM

    As I can understand you will have the same options in your drop down fields and you want to know how many times an option was selected. 

    If this is what you are looking for then you would need to add a text box per each option in your drop down field: 

    How to count selected options from a drop down field? Image 1 Screenshot 40

    You will need some conditions in order to add the correct value based on the selection, you will use the update/calculate condition: 

    How to count selected options from a drop down field? Image 2 Screenshot 51

    How to count selected options from a drop down field? Image 3 Screenshot 62

    The screenshots are based on a form with radio buttons, but it will work the same for drop downs. You can see how it works on this sample form: https://form.jotformpro.com/71135255072954 

    Please, give it a try and let us know if you have any question. 

  • Impacct
    Replied on June 21, 2017 at 7:20 AM

    Maybe I am missing something, but wouldn't that just result in a value of 1 no matter how many times an option is selected? What function is adding 1 each time an option is selected (there are 60 drop downs so the value of any text box can be between 1 and 60)? I only see a function to insert 1.

  • Impacct
    Replied on June 21, 2017 at 10:33 AM

    Also, the conditions don't seem to be able to work with the survey values entered for the field. 

    I really don't want to write conditions that exempt 67 of the available options in order for this to work.....

  • Nik_C
    Replied on June 21, 2017 at 10:45 AM

    Yes, that is correct, the example that my colleague provided will count one click per one field. 

    Unfortunately, what you need is to count per selection, we don't have such built-in solution. That might require some additional coding to make it work.

    But please allow me some time to try to find a workaround for you.

    I'll get back to you as soon as possible.

    Thank you!

     

  • Nik_C
    Replied on June 22, 2017 at 10:16 AM

    Thank you for your patience. 

    Since we don't have a built-in solution for what you need, I tried to create a workaround.

    1) For each option in each drop down field assign a calculation value, and it should be number 1:

    How to count selected options from a drop down field? Image 1 Screenshot 30

    So if you have four options you should put four numbers, if you have 10 then ten and so on.

    2) We create a condition like this:

    And the output is regular text field:

    How to count selected options from a drop down field? Image 2 Screenshot 41

    This solution will require creating the above condition for each drop-down field, but not for each option.

    And here is my test form, please check it: https://form.jotformpro.com/71714569613966

    Please let us know if this could work for you.

    Thank you!

  • Impacct
    Replied on June 22, 2017 at 10:26 AM

    Thank you,

    Just to confirm, in the above example, a1, a2, a3, and a4 represent the names of the dropdown fields, right?

    Also, I notice in the example form everything is adding up into one count box. 

    I actually need this to be split into 2 count boxes based on the calculation value (value 1 goes into one box, value 2 goes into a second box). Is there a way to write the condition for that?

    Thanks again,

  • Support_Management Jotform Support
    Replied on June 22, 2017 at 12:27 PM

    Just to confirm, in the above example, a1, a2, a3, and a4 represent the names of the dropdown fields, right?

    You're correct, these are the Dropdown field labels.

    Also, I notice in the example form everything is adding up into one count box.

    That's also true. Nik has setup his demo form to count the selections made on all 4 Dropdown Fields. If you only filled out 2 out of 4 of the Dropdowns in his demo form, the Count Textbox will only show 2.

    I actually need this to be split into 2 count boxes based on the calculation value (value 1 goes into one box, value 2 goes into a second box). Is there a way to write the condition for that?

    I'm not sure what you meant by splitting them into 2 Count Textboxes. I'm asking because all 4 Dropdown Fields in Nik's example will only yield the same results regardless. Any selection made will result to a value of 1. Splitting them into 2, 3 or even 4 Count Textboxes will yield to the same count.

    You can create separate conditions if needed and only count specific Dropdown Fields, is that what you mean? Unless we're missing something from your requirement, consider the following example:

    4 Dropdown Fields named a1 to a4

    2 Count Textboxes named Count 1 and Count 2

    2 Conditions:

      - Condition 1 will only consider a1 and a2

      - Condition 2 will only consider a3 and a4

    How to count selected options from a drop down field? Image 1 Screenshot 20

    Result: https://www.jotform.com/71724701778967 

  • Impacct
    Replied on June 22, 2017 at 5:01 PM

    Let me see if I can explain this a bit better.

    This is the form being worked on: https://www.jotform.com/build/70874086204154

    It is very long and complex, and I know the more complex it gets the more likely it will be to crash when loading or take along time to load. 

     

     

    The conditions I am trying to build will apply to the country selection dropdowns on page 3 of this form.

    1. I have 60 dropdowns with 158 options each. 

    2. Each option is assigned a calculation value of either 1 or 2 on the surveying tab (see the country 1 dropdown settings on the survey tab)

    3. I want the options with values equal to 1 to be tallied in text box A

    4. I want to options with values equal to 2 to be tallied in text box B

     

    Originally, I thought I could structure the calculation conditions to say:

    a) If dropdown 1 calculation value is equal to 1, insert +1 into text box a.

    b) If dropdown 1 calculation value is equal to 2, insert +1 into text box B.

    and then just repeat this condition for each country dropdown. 

     

    The issue is since the calculation values don't show up in the calculation condition, I am not sure how to do this or even if it can be done. 

     

    I have been building large conditions to get around the issue (see condition 10) but they take a lot of time to build since I have to redo all 67 options each time I change the country dropdown they apply to. 

     

    Being able to use the calculation values they way I described above will let me build much smaller conditions which even though they will still need to repeated shouldn't be such a burden. 

     

    Please let me know if you have any questions.

    Really appreciate your help with finding a better way to do this.

     

    Thanks again

     

    -Ilana

  • Mike_G JotForm Support
    Replied on June 22, 2017 at 7:32 PM

    We appreciate you explaining this further. Like what my colleague, Nik_C, mentioned above, this feature is not yet available with our Conditions. However, I have a workaround for you that would only require you to have one additional Input Table field (Matrix field) and one additional Short Text field (textbox field) per drop-down. The number of rows in the Input Table field (Matrix field) depends on the number of drop-down fields involved. Also, it would require you 3 additional conditions per drop-down field.

    Note: The additional Input Table field and Short Text fields should be hidden in the form.

    Here's the form that is based on your example when you opened this thread.

    https://www.jotform.com/build/71726561465966

    Below is how the workaround is done.

    Step 1 — Adding the textbox fields and the input table 

    How to count selected options from a drop down field? Image 1 Screenshot 80

    Note: The selected Input Type of the Input Table should be "Text Box".

    Step 2 — Creating conditions

    The first set of conditions will be necessary to pass the calculation value of the selected option in a drop-down field to its corresponding additional textbox field

    How to count selected options from a drop down field? Image 2 Screenshot 91

    The second set of conditions will fill the first column of the input table field if the calculation value that is passed to the textbox field is equal to 1.

    How to count selected options from a drop down field? Image 3 Screenshot 102

    For example, if the textbox field (1) associated with drop-down field 1 is equal to 1, it will fill the first "text box" of column 1.

    Selecting the Matrix Table (Input Field) for the final output in the condition will let you choose a sub-field (text box) where you would want the output to be placed.

    How to count selected options from a drop down field? Image 4 Screenshot 113

    Similar to the second set of conditions, the third set will let you fill the second column of the input table field if the calculation value that is passed to the textbox field is equal to 2.

    How to count selected options from a drop down field? Image 5 Screenshot 124

    The last set of conditions will calculate the total of the values in the textbox of the Input Table (Matrix Table) per column if any of the drop-down fields are filled.

    How to count selected options from a drop down field? Image 6 Screenshot 135

    The Column 1 total will go to Cell A and the Column 2 total will go to Cell B.

    To select what textbox fields in the Input Table field should be added to get the value for each cell, please refer to the screenshot below.

    How to count selected options from a drop down field? Image 7 Screenshot 146

    I hope this helps. If you have other questions or concerns regarding this, please feel free to contact us again anytime.

  • Mike_G JotForm Support
    Replied on June 22, 2017 at 7:37 PM

    I would like to apologize for I have given you the link to the builder page of the form.

    Here's the correct direct link to the form so you can test it.

    https://form.jotformpro.com/71726561465966

    I did not hide the Input Table field and Short Text fields purposely for testing.

  • Impacct
    Replied on July 17, 2017 at 1:40 PM

    Thank you,

    This is working for the most part. For some reason some of the conditions don't seem to be working. 

    For example, the conditions that enter the value in the matrix table for countries 13-20 has stopped working. Can you please help me figure out what is wrong?

    https://www.jotform.com/build/70874086204154

    Thanks again,

    Ilana

  • Impacct
    Replied on July 17, 2017 at 1:51 PM

    nevermind - I see what I did wrong. Thanks again!

  • Nik_C
    Replied on July 17, 2017 at 1:54 PM

    Great, I'm glad you were able to make it work. 

    If you have any further concerns or questions do not hesitate to contact us.

    Cheers!