Skip to main content
ls_rbls
Community Expert
Community Expert
June 20, 2019
Answered

How to add the listed items from a group of combobox menus in a calculated text field

  • June 20, 2019
  • 1 reply
  • 2349 views

I am currently struggling in figuring out how to create an ordering form with calculated fields that will allow me to add the valueAsString from a group of comboboxes.

For example, my form has three combo boxes for the user to select an array of different meal kits for breakfast, lunch and dinner for that day.

A separate text field allows the user to enter the total headcount for diners consuming the meal kits.

The breakfast combobox offers a selection of either  pork-free, religious meal, regular-breakfast

The lunch combobox offers a selection of pork-free, religious meal, regular-lunch

The dinner combobox offers a selection of pork-free, religious meal, regular-dinner

Ona separate text fields I  need to calculate the total of pork-free meals selected for breakfast, lunch and dinner; the total of religious meals selected for lunch; and the total regular meals for brekfast, lunch and dinner.

The reason why is because each mealkit provides different amount of kits per box. So if I have 50 diners ordering religious meal for breakfast and say that box contains 9 mealkits per case,  I have to divide 50 diners by 9 which equals 5.55 rounded to a total of 6 boxes.

The same for lunch and dinner.

So my predicament is to get a separate field that can add automatically  all the selected  meals from breakfast, lunch and dinner that are the same selection on each combobox.

This topic has been closed for replies.
Correct answer try67

For all of them together


OK. First of all, rename the first fields in each group to B1, L1 and D1, and then you could use this code to perform the count (place it as the custom calculation script of the text field where you want to show the results):

var v = "RELIGIOUS, KOSHER";

var total = 0;

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

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

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

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

}

event.value = total;

The value in the first line is what you're counting.

1 reply

try67
Community Expert
Community Expert
June 20, 2019

So basically you want to count how many times a specific item was selected from multiple drop-down fields?

What are the names of those fields?

ls_rbls
Community Expert
ls_rblsCommunity ExpertAuthor
Community Expert
June 21, 2019

Thanks for your quick response. By the way, I've been following some of

your posts where it has been suggested to some users whith a similar

challenge w to rename each combo box fields in a sequence.

On the other hand, I was able to work around this issue by creating

individual hidden calculated fields with the following script for the

pork-free mealkit selection.

For example, to get the total number of boxes I need to order for a

selected Lunch meal, my hidden text field has the following calculated

script:

if (this.getField("L").value == "pork-free") {

event.value = (this.getField("HC1").value/9);

}

else event.value = 0

So 50 diners divided by 9 pork-free mealkits per box = 5.55 total number

of boxes that I need to order

To round it up automatically , I included the following custom format

script:

var v1 = +getField("Text9").value;

event.value = Math.ceil(v1);

So I get a total 6 boxes of pork-free mealkits that I need to order

Now, on a separate text field I just choose from the Calculate

tab, "Value is the SUM(+) of the following fields" and this gives me

the total of what I'm looking for.

But after reading some of your posted solutions, then I came across with

the next problem: doing hidden calculated fields works great to just add

and divide the total headcount by meal type per total mealkits per box as

long as it is done for one menu item ony.

If I get a customer who wants to combine and/or order different mealkit

types for breakfast, lunch, and dinner for up to 40 days in a row then my

little methos is not practical anymore since it slows down the pdf form

dramatically (not to mention that I also would have to add way too many

hidden calculated fields just to accomplish the abovementioned purpose. So

I need a calculated field that is able to sum up for the user the total of

any meal kit selected on each combobox.

The menu selection table in my form is organized as shown below, where

Consumption Dates and Headcount columns are just plain text fields which

allows the user to enter its own info; then to the right are the comboboxes

to select a meal type for the meal to be consumed that day.

To answer your question with no more rodeos, the name of the dropdown

menu fields for Breakfast, Lunch and Dinner are as follows:

Consumption Date Headcount (total diners)

Breakfast Lunch Dinner

date_picker1

HC1 B

L D

date_picker 2

HC2 B1

L1 D1

date_picker2

HC3 B2

L2 D2

try67
Community Expert
Community Expert
June 21, 2019

I'm sorry, I don't follow what you want to achieve, exactly. Please try to describe it in the most concise way possible, or share the file with us.