Expand my Community achievements bar.

Java script formula for dropdown list to determine possible selections in another dropdown list

Avatar

Former Community Member

I have seen related if not identical posts in here but I cannot still figure out the solution. I would appreciate any help. I am using LiveCycle ES2.

I have two dropdown lists: Province and City

Province contains (say) Alberta, Toronto, Manitoba
City has (say) A, B, C, D, E, F, G, H, I, J, K

I want the City (dropdown list) to behave in this way:

  • If I select Alberta, only A, B & C would be available for me to select
  • If I select Toronto, only D, E, F & G are available for selection
  • If I select Manitoba, only H, I J & K are available for selection

How do I write the script for this? Again, thank you very much for the help.

PeeGee

1 Reply

Avatar

Level 10

Hi,

Try this JavaScript in the preOpen event of the city dropdown (which I have called CitiesDropDown and called the provinces one ProvincesDropDown)

var cities = [];

switch (ProvincesDropDown.rawValue)

{

    case "Alberta":

        cities = ["A", "B", "C"];

        break;

    case "Toronto":

        cities = ["D", "E", "F", "G"];

        break;

    case "Manitoba":

        cities = ["H", "I", "J", "K"];

        break;

}

CitiesDropDown.clearItems();

cities.forEach(function(element) { CitiesDropDown.addItem(element); });

Regards

Bruce