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

How to auto populate quantities using 2 drop-down menus

Community Beginner ,
Aug 25, 2023 Aug 25, 2023

Hi, new business owner & new Adobe user here. A couple days into using it & I feel like what I'm looking for is probably super simple for most. If I get the answer here, it will save me an embarrassing amount of time trying to figure it out myself. I'll try my best to explain.

We're creating a form for large quantity clothing orders.
It has 2 drop-down menus (Style: Adult, Youth) and (Size: xs through 4xl) followed by the quantity column. At the bottom of the form I'd like it to auto populate the quantity breakdown - how many Youth XS, how many Adult XS, etc. 

I have the items & values done in the drop downs but I have know idea what the custom script would look like to calculate totals.

Any help would be greatly appreciated.

thanks!

 

 

TOPICS
How to , PDF forms
2.9K
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 ,
Aug 25, 2023 Aug 25, 2023

It's actually not that trivial. You would need to use a for-loop to iterate over all the fields, checking each pair for a certain value, and then incrementing the value of a counter variable if they match what you're after, applying the value of that variable to the total field at the end of the process.

If you let us know what are the names of the fields involved I could help you with a sample code for this.

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 ,
Aug 25, 2023 Aug 25, 2023

I wasn't expecting such a quick response & I really appreciate it. It sounds like this is something i wouldnt have figured out on my own. I attached photos of the form hoping that is more helpful then an explanation from me. I made the export value for each selection in the drop-down menus 1

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 ,
Aug 26, 2023 Aug 26, 2023

OK, then you can use this code to count the number of YOUTH XS selections, for example:

 

var count = 0;
for (var i=1; i<=26; i++) {
	if (this.getField("STYLE"+i).valueAsString=="YOUTH" && this.getField("SIZE"+i).valueAsString=="XS") {
		count++;
	}
}
event.value = count;

 

Place it as the custom Calculation script of the text field where you want the result to appear.

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 ,
Aug 26, 2023 Aug 26, 2023

Thanks so much! I'm excited about this working. I entered the code as the custom calculation script in the small text field at the bottom, it appears like it'll work but when i enter totals it still shows 0 in the text field. Is there something else I should change? i attached a photo

thanks again

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 ,
Aug 26, 2023 Aug 26, 2023

I made a small mistake, but it should still show "1" in the output fields... For it to sum the quantities you should change this line:

count++;

To:

count+=Number(this.getField("QTY"+i).valueAsString);

If it still doesn't work you'll need to share the actual file for further help.

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 ,
Aug 26, 2023 Aug 26, 2023

I tried & it didnt work, I've attached the file. I appreciate your help but i dont want to take up much more of your time. If it doesnt work, i can have clients manually enter the numbers. There seems to be frequent errors when the info is entered manually, I was hoping to reduce the errors this way. But it's not a big deal if it doesnt workout.

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 ,
Aug 26, 2023 Aug 26, 2023

The issue is with the export values you applied to the items in your drop-downs. They are the actual values of the fields, but since they are all the same ("1") it's impossible to know what item is selected...

Remove them, or replace them with unique values. If you remove them the code I provided should work.

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 ,
Aug 28, 2023 Aug 28, 2023
LATEST

It worked! I'm super grateful, saying thankyou doesn't seem like enough. But thanks again!

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