Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Joining 2 fields

Avatar

Level 2

Hi,

I am trying to make a form in which I have 2 dropdown lists. What kind of script should I write so I can choose from the first dropdown list an item and another item will be selected from the other list?

Thanks

8 Replies

Avatar

Former Community Member

Do you want drop-down 1 to completely change the values available in drop-down 2, US/Canada and states/provinces, for example? Or do you simply want the selection in drop-down 1 to automatically set the default value of drop-down 2?

Steve

Avatar

Level 2

Well, if I have in drop-down green it will give me apple, if I change to yellow the other drop-down will give me banana.

Avatar

Former Community Member

If there is a one-to-one relationship between the two drop-downs then it is very simple, if the drop-downs are declared to specify item values.

// form1.page1.subform1.fruit::calculate - (JavaScript, client)

this.rawValue = form1.page1.subform1.colour.rawValue;

Steve

Avatar

Level 2

Okay,

If it one to many?

Edmon

Avatar

Former Community Member

If you expect 'apple' to define a list of possible apple colours and 'banana' to define a list of possible banana colours, then you are referring to the first scenario I referenced above. If you pick 'U.S' the second drop-down contains states, if you pick 'Canada', the second drop-down contains provinces.

Is your expectation different than that?

Avatar

Former Community Member

That is a whole different level of complexity.

Steve

Avatar

Level 2

Hi, Using the arrays looks great for what I need to do too.

But the data is hard coded and thus not as flexible

eg: you use var caCodeStr = "Canada,AB,BC,MB,NB,NL,NS,NT,NU,ON,PE,QC,SK,YT";

If this data was in a relational database that I want to connect to

One table with CountryID and CountryName and other data

Another table with CountryID, StateID, StateName and other data

Question:

How would I load the required data from these tables to populate the arrays?