populate text field from three dropdown selections

New Here ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

I have a document with three dropdowns and I need to populate a text field based on them.

One drop down is a description, one is size, and one is the color. I need different combos of these fields to populate a text field with the correct item code.

For example: If a user selects "boots" from the first drop down, "7" from the size dropdown, and "blue" from the color drop down ---it should show the item code BB7456 in the item code text field. This item code would also be different if a different size or color was chosen.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

266

Likes

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

Adobe Community Professional , Jan 23, 2019 Jan 23, 2019
Since it's 3 characteristics to to 1 item code, the way to organize a lookup table would be to use the item code as the member name of an object. Like this:var ItemLookup = { BB7456:{item:"boots", color:"blue", size:7},                            BB7457:{item:"boots", color:"red", size:7},                            BB7458:{item:"boots", color:"blue", size:9},                                .... etc....                        };Then you need a lookup function that loops over all the entries to f...

Likes

Translate

Translate
Adobe Community Professional ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

Is the item code constructed from component parts? In other words, can values from the first, second, and third drop-down lists be concatenated into the right code or are you going to need a lookup table?

Likes

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
New Here ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

Pretty sure a lookup table. It's a catalog type thing where each product has a item code number based on the description, size and color you choose.

Likes

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
Adobe Community Professional ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

That's going to be a bit more complicated. Do you then also want the lists to be dependent on each other? If I select an item from the first list, will the items in the second change? Same with the second and third?

Likes

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
LEGEND ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

You should tell more about how you create the full result. We need to know exactly were each value goes in the result string and how the additional values are determined.

Will the text fill if any of the 3 choices are omitted or not selected?

Are any of the choices being assumed to have a default value?

Likes

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
Adobe Community Professional ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

Since it's 3 characteristics to to 1 item code, the way to organize a lookup table would be to use the item code as the member name of an object. Like this:

var ItemLookup = { BB7456:{item:"boots", color:"blue", size:7},

                            BB7457:{item:"boots", color:"red", size:7},

                            BB7458:{item:"boots", color:"blue", size:9},

                                .... etc....

                        };

Then you need a lookup function that loops over all the entries to find the correct one

This codes is for a custom calculation on the field that displays the code

var cProduct = this.getField("ProductName").value;

var cColor = this.getField("ProductColor").value;

var cSize = this.getField("ProductSize").value;

var cItemCode = null;

for(var cd in ItemLookup)

{

    if((ItemLookup[cd].item == cProduct) && (ItemLookup[cd].color== cColor) && (ItemLookup[cd].size == cSize)

    {

            cItemCode = cd;

            break;

      }

}

event.value = cItemCode;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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
New Here ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Excellent! Thanks so much!

Likes

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
New Here ,
Jan 27, 2019 Jan 27, 2019

Copy link to clipboard

Copied

How would I change this code so that I could have two rows of the three dropdowns and item text field?

I was able to use this code to create one text field that worked with the drop downs but I'm not sure how to change things so that a second row would work.

Thanks!

Likes

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
Adobe Community Professional ,
Jan 27, 2019 Jan 27, 2019

Copy link to clipboard

Copied

LATEST

The trick is in generalizing the parts of the code that deal with specific field names.

First, name the fields so they can automatically recognized as being part of a group. For example, prefix all the names with the row number. i.e. "Row1.ProductName"

If you don't have many rows the easy thing to do is to then just copy the calculation script to the next field that that needs it and change the field names. But if there are many rows, the script should be placed in a document level function. The code needs to be modified so that the field names can be automatically generated. For example, pass the row name into the function. Then all of the fields that concatenate the dropdowns call this function, passing in the appropriate row number.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

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