I have 2 drop down lists on the same form, let's say A & B. How do I control the entries available in list B based on what a submitter selects in list A?
Question
Question
Control Drop Down List Entries Based on a Previous Drop Down Selection
Answer
If you're looking to set this up using hard coded values instead of doing a database lookup, then one possibility is to create drop down A with the list of values. Then for each value in the list, create a subsequent drop down B1, B2, B3, etc. that corresponds to the possible values that should be displayed based on what was selected for A. Then you can create a field rule to show the correct drop down B field based on what was selected in A. Note that this can be cumbersome and so it's highly recommended to use a database lookup for this instead.
Replies
This sounds like a straightforward lookup rule. Check out the online help:
Just confirm, this is for Laserfiche Forms and I don't have the lists in any database tables. They're hard coded within the form itself.
Is there still a way to control what a submitter sees in DropDown B based on what is selected in DropDown A?
For cascading dropdowns with static data you can do:
We have two dropdowns department and division.
DEPT DIV
0001 011
0002 011 036
0003 012 013 015 026
Add the dropdown DEPT and add 0001, 0002, 0003 for the choices (options) LF creates an ID like q147 find yours.
Add DIV dropdown you don't need to add any options id is q148.
Open Javascript tab
$( document ).ready(function() {
//Array to use in DIV
var locations = {
'0001': ['011'] ,
'0002': ['011' ,'036'] ,
'0003': ['012' ,'013','015' ,'026'] ,
}
//When DEPT value changes
$('#q147').change(function () {
//return the location that correspond to the selected department
var lcns = locations[$('#q147 select').val()] || [];
//remove all options in DIV Dropdown
$('#q148 select').find('option').remove();
//populate the DIV dropdown with the result
jQuery.each(lcns,function(i, val) {
$('#q148 select').append(new Option(val, val, false, false));
});
});
});
Hey Eddie,
Are you trying to accomplish this task on a form that was created in Laserfiche Forms? Or is this for a list field in the metadata of a document?
If this is for Forms, use the help files listed above by Scott.
If this is for fields within a template, check out there help files on Dynamic Fields.
This is for Laserfiche Forms and I don't have the lists in any database tables. They're hard coded within the form itself.
Is there still a way to control what a submitter sees in DropDown B based on what is selected in DropDown A?
If you're looking to set this up using hard coded values instead of doing a database lookup, then one possibility is to create drop down A with the list of values. Then for each value in the list, create a subsequent drop down B1, B2, B3, etc. that corresponds to the possible values that should be displayed based on what was selected for A. Then you can create a field rule to show the correct drop down B field based on what was selected in A. Note that this can be cumbersome and so it's highly recommended to use a database lookup for this instead.
Hey Eddie,
Yes you can still do this in Forms! Here's the link you'll need explaining more about Field Rules.
It basically works like this. Imagine you have a drop down field called "Make" (as in make of a car). Listed here are several options: Honda, Toyota, Mercedes-Benz, etc... You'll want to create several drop down fields under this Make field, one called "Honda Model", another called "Toyota Model" etc.
When Honda is selected in the "Make" field, use field rules to hide "Toyota Model" and "Mercedes-Benz Model" and ONLY show "Honda Model". Repeat these rules with the appropriate values until selecting the make of a car will ONLY show the models that make sense.
Hopefully that can help get you started in the right direction, but let me know if you have any other questions!
Alexander,
How can this be achieved while using lookup rules? I have database table as the source, and would like to populate values of a drop down based on the selection of it's previous drop down.
Thanks
Here's an example:
Below is a table in my database
On my form, I have two drop down fields: one for the sport and the other for the team. This is how I would configure the lookup rule in Forms
Fill the "Sport" drop down field with the values from the "Sport" column in the database table. Then when the "Sport" that gets selected matches the "Sport" in the table, fill the "Team" drop down with the values from the "Team" column in the database table. The result looks like the following
I tried this and it worked partially. I have about 5 columns in a table on the form as well as database, and the selection in the first column decides the values in the second, and so on. In this case this method seems to fail. Is it a limitation of the look up rules functionality or am I doing it wrong?
I even tried nesting the rules, so to speak, by adding one when condition more than the previous rule.
Depending on Column 1, Column 2 choices are filtered, and depending on column 1&2, column 3 data is filtered and so on...
Here's an example of a three-tiered dynamic field configuration in Forms for selecting a state, city, and neighborhood.
This works for me when the three drop down fields are columns in a table. The rules use the same logic you describe. The state drop down is always filled with the "state" values. The city drop down then depends on what the state is. Finally, the neighborhood drop down depends on both the state and the city.
Hey Andrew,
This is exactly what I tried, but didn't work. Now that I see that I was on the right track I'll dive a bit deeper and check out where I or the data source might have gone wrong.
Thanks a ton!