Highlighted

related drop-down lists

Participant ,
Jun 05, 2018

Copy link to clipboard

Copied

I have two dropdown lists whose contents are extracted from a database.

But I would like that when I select a value in the first, the content of the second adjusts because according to the choice in the first list, I will not have the same elements in the second.

illustration: display the department of a selected region. So I have a database with two tables, a table for the regions, a second for the departments. By selecting a region in the first list, I will display the second list corresponding to the departments of the selected region.

Tank you

Views

275

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

related drop-down lists

Participant ,
Jun 05, 2018

Copy link to clipboard

Copied

I have two dropdown lists whose contents are extracted from a database.

But I would like that when I select a value in the first, the content of the second adjusts because according to the choice in the first list, I will not have the same elements in the second.

illustration: display the department of a selected region. So I have a database with two tables, a table for the regions, a second for the departments. By selecting a region in the first list, I will display the second list corresponding to the departments of the selected region.

Tank you

Views

276

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 05, 2018 0
LEGEND ,
Jun 05, 2018

Copy link to clipboard

Copied

Easy to do, but it won't be a strictly CF solution.  You have to use JavaScript (or jQuery) to do it.

Basically, you load the page with the first select fully populated by the database.  The second select should have no options.

Set the onChange of the first select to use AJaX to make the call to a .cfm or .cfc that will get the related department based upon the value of the region select, and then add the options to the second select.

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 05, 2018 0
Participant ,
Jun 06, 2018

Copy link to clipboard

Copied

Do you have an example for this to be more meaningful?

cordially

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 06, 2018 0
LEGEND ,
Jun 06, 2018

Copy link to clipboard

Copied

Hi, ZNB,

Raymond Camden has an excellent blog post about related selects.  This example is using jQuery.

https://www.raymondcamden.com/2011/05/05/Related-selects-in-jQuery-an-example

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 06, 2018 0