Skip to main content
haleym66925479
Participant
January 23, 2019
Answered

populate text field from three dropdown selections

  • January 23, 2019
  • 1 reply
  • 1221 views

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.

This topic has been closed for replies.
Correct answer Thom Parker

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;

1 reply

Joel Geraci
Community Expert
Community Expert
January 23, 2019

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?

haleym66925479
Participant
January 23, 2019

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.

Joel Geraci
Community Expert
Community Expert
January 23, 2019

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?