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

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

Community Expert ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.0K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jun 22, 2019 Jun 22, 2019

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 firs

...

Votes

Translate

Translate
Community Expert ,
Jun 20, 2019 Jun 20, 2019

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 20, 2019 Jun 20, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

script combo box.png

This is the table I was trying to describe .

In short, yes, as you asked before I need to count how many times a specific item was selected from multiple drop-down fields.

The name of the fields are shown in the image below:

name of the drop down menus.png

B, B2, B3, B4, B5  column is for all breakfast meals

L, L2, L3, L4, L5 for all lunch meals

D, D2, D3, D4, D5 for dinner meals

Votes

Translate

Translate

Report

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 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

Do you want to count it per meal type (ie, just Breakfast, or just Lunch, etc.) or for all of them together?

Votes

Translate

Translate

Report

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 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

For all of them together

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

try67,

Thank you so much for your time and effort!

The only hiccup I'm running into  is that when I changed the field names as you recommended from B1 through B5, L1 through L5 and D1 through D5 respectively; for some reason B1 is not getting calculated by the script.

It seems like the field is completely ignored and I have already changed its name a few times; I  even deleted it and created a new field and nothing.

I have a total of 15 drop list menus and your script substract or add as I select or clear the fields perfectly except that  for some reason  B1 is left out and I always get no more than 14 counts when all the fields are selected with the same item

Could it be that the issue is somewhere else throughout  my form?

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

Did you change the code in any way? Can you share the file with us?

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

No changes to the code. I just renamed the value to be counted in the first line and it works good.

And yes I can share just that portion of the document as an extract. I don't have authorization from my job to send the whole document.

Should I send it to try6767@gmail?

If it helps in any way, I've ran into this similar problem before when copy and pasting fields from another form that I was working on instead of building the fields from scratch and assigning them with  their own name in the new form

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

Also if I wanted to right-click on any of those drop list menu  and select "Create Multiple Copies" this is what I get:create copy error.png

The document only allows me to copy and paste as you normally would with any editing tool but not with the other method.

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

Yes, you can send it to that address and I'll check it out.

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

Try67,

I was able to resolve the issue.

Even when your script used the "ValueAsString" assignment, I noticed that I had previously assigned export values to each meal type and  forgot to clear them out; this took me a while to figure out.

The other issue was the duplicated drop list fields throughout the document that I had to delete.

And lastly, I recreated all of the drop down list menus from scratch to make sure there were no old calculating scripts lingering and then rename them with the original name values that we used in your script.

I am still sending you  an extracted copy of this table for your future reference.

I truly  appreciate what you do and all of the other community professionals that support your work.

Votes

Translate

Translate

Report

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 22, 2019 Jun 22, 2019

Copy link to clipboard

Copied

Yes, the "valueAsString" property will return the field's export value, if one is present.

Anyway, glad to hear you got it all sorted out!

Votes

Translate

Translate

Report

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 ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

LATEST

I am almost done with the document, just wanted to let you know I have not forgotten to send you the file. You will probably be getting it over this weekend

Votes

Translate

Translate

Report

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