Expand my Community achievements bar.

Dynamic Drop Down

Avatar

Former Community Member
New to LiveCycle, and am looking for a way to have a dropdown box only display data based on the entry in another dropdown box. For example if I have a State Dropdown, that list's all the States and then a City Dropdown that would only List City's within the State selected in the State Dropdown.
18 Replies

Avatar

Former Community Member
Where are the list of cities going to come from .....will you hard code it? Are they in a DB?



Doing what you ask is not that difficult, getting the data to populate the DD is the key.

Avatar

Former Community Member
Hardcode would be prefered, users that will use the form, will not always be connected to a network, when they are filling the form out.

Avatar

Former Community Member
Then it is simply a matter of coding .... On the exit event of the 1st dropdown you can check the rawValue property (to let you know what the user selected and then use a select statement (Javascript case statement) then programatically add the items to DropDown2.

Avatar

Former Community Member
There is a complex example that ships with Designer. Goto the install directory, then EN/Samples/Purchase Order/Dynamic Interactive/Forms



The country and state/province does what you want.

Avatar

Former Community Member
Hi, been trying to follow the example in the Purchase Order Form, but very much an amateur at writing code. My main problem is I don't understand where the information to populate the lists comes from - is it in the scripting, or is there another location for information that I don't know about?

Similarly to the other guy, I need to have it hardcoded, but I'm just a gumby in writing code. Have read through the FormCalc user guide, and it simply doesn't make sense when you have no programming background!

Hope I can get some help,

Thanks!

Avatar

Former Community Member
The code is in a scripting object and it uses a very complex means to do it. If you are not familiar with code then you will not understand it. Can you hard code the values in the object itself?

Avatar

Former Community Member
Hi Mj Harvey,

The list comes from the script. Script is defined in the Script Object named "countryScript". myCountries array holds the countries with states.

myCountries[1][0] = "Canada"; // The first data value is the country name,

myCountries[1][1] = "Alberta"; // the rest are states/provinces.

myCountries[1][2] = "British Columbia";

myCountries[1][3] = "Manitoba";



In the change event of country field,

countryScript.getStatesOther(xfa, drpOrderedByStateProv);

is called. If you search the getStatesOrder function, by using addItem function new dropdown is filled.

Hope you catch.

Asiye

Avatar

Former Community Member
Hi Asiye,

I "kinda" get what you mean, but I don't know enough about naming of Script Objects, fields and using the addItem function to know how they link together - think dumber for me!! I understand how to have the different countries and states being input into an array, but where does the "array" fit into it? I have looked at the scripts in the Purchase order form, and they say:

'countryScript.getCountries(this);' but I don't know where or what 'this' is. The other thing is, I don't know the definition in this sense of what 'hard code' is. I thought I did, but apparently not.



I feel like I'm almost getting it, but sorry, not quite there yet. Could I ask for a little more help?



Thanks to both of you so far.

Avatar

Former Community Member
Hi Mj Harvey,

In Script objects you can define your general scripts of your form and functions. You can right click of the form in the hierarchy palete and clicking "Insert Script Object" will create a new script object with blank name. This object will be under the "Variables" in the hierachy. You can rename this object by F2 to your desired (as myScriptObject).

When you click on the script object on the hierachy, in the script panel you can define your arrays and functions. Define an double sized array as stateArr (as in Purchase Order). After define the same function stateOrder as in Purchase order.

In the dropdown change event, in script panel: you can call this function as myScriptObject.stateOrder(....) as in Purchase order. If you could not achive you can send me email asiye.aydin@gmail.com.



Asiye

Avatar

Former Community Member
I need to do something slightly similar.



I have two drop-downs for a hotel reservation-type application. The first is for the check-in date, the second for check-out date. If check-in is input first, check-out must have a later date and vice versa.



Is this an easy effect to achieve?



Many Thanks

Avatar

Former Community Member
Yes ....it is easiest to deal with dates when yu convert them to an epoch (the number of seconds that have expired since a set moment in time). If you do this as long as the checkout date number is later than the checkin date then you know you are OK. There are commands for this is both FormCalc and JavaScript.

Avatar

Former Community Member
Thanks.



How about if I want to achieve the same effect but with integers rather than dates? For example, two drop-down boxes with values from 0-9 - the second drop-down cannot contain a value less than the first drop-down.

Avatar

Former Community Member
That is easier that the previous means as you can get the DropDown.rawValue property and compare it to the 2nd one ....a much easier set of commands.

Avatar

Former Community Member
Hello,



i have a pull down menu and 2 other pull down menus hidden. When a choice is chosen from the first menu I would like one of the other ones to appear. Can someone help me out with a statement I can do this with. I think Its an If statement I'm looking for.

1st menu only has 2 items in the menu.



I got it to work with a radio button useing the click feature:

Subform4.presence = "hidden";

Subform3.presence = "visible"



I really want the pull down menu instead of the radiobutton.



Please help, thanks Lucy

Avatar

Former Community Member
Paul,

Thanks for the recommendation to use the Purchase Order sample -- the script object worked well for my application. However, there is one problem with this script. If you select "Canada" as the country and "British Columbia" as the state/province, and then change the country to "United States", "British Columbia" remains in the state/province field unless you reselect a state. This means a non-permitted country/state combination can be retained in the form.



Do you have a fix that clears the state field when the country field is changed and then populates the drop down with the appropriate states? Thanks for your help.

Dale

Avatar

Former Community Member
Hi Dale,

You can make state combobox empty in the change event of country combobox. In the change event check the previous value with changed value, and if they are not equal, make state combobox empty.



If you need the script solution as well, you can mail me.



asiyegunaydin@kgc.com.tr

Asiye