Forums

dropdown based on a value of another dropdown

Mazin7 17 Nov, 2014
Hi!
I need your help a second time!
I have a dropdown. This dropdown is made with a costum code. When the site is on load, the dropdown retrieves data from a mysql database and shows the results in the list. Further in the costum code is defined, what elements are shown next, when a assigned value from the dropdown is chosen. So this is what my first dropdown does.

Now the my problem:
I want a second (perhaps still more) dropdown, which depends on the selected value of the first dropdown. When a value of the first dropdown is chosen, i want to pick this value, to fill it in a sql query for the database query for the second dropdown.

For example: In the first dropdown the value "City" is chosen. Then i want a second dropdown, whose values i get with the sql query "select * from City".

By looking for a solution for this problem, i found out, that this can be handled with Ajax and JQuery. But i ask myself, if there is a more simple solution with chronoforms, because i haven't any experience with Ajax or JQuery.

I would be very grateful, when someone can help me with that!

Regards!
Mazin7 18 Nov, 2014
nobody any ideas? :/
Max_admin 18 Nov, 2014
Hi Mazin,

v5 has a set of demo forms, one of them is about "dropdown dynamic data", this explains how to load the dropdown options from the database.

Another one named "dynamic dropdown", this one explains how to load the options of a dropdown based on the value of another one, it uses AJAX, but it not a database query, you will need to modify this example and use a "db read" action!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Mazin7 20 Nov, 2014
Hi Max,

thanks for your help!
I want to do that like you say, but i have already problems to get data of an external database with db read.
When i have put in the paramters for the external database, the tables of my databases are loading right. But what then?
How can i execute my own sql query with db read? I'm not getting it sry :/

Regards,
Mazin
GreyHead 20 Nov, 2014
Hi Mazin,

Please see this FAQ for the code to connect to a remote database if that is what you need. Once you have the connection you can run any MySQL query in PHP.

Bob
Mazin7 21 Nov, 2014
Hi Bob,
it's not the problem to connect to my mysql database. In the external database tab of db read i put my connection parameters. Then i can select a table of my external database. But what then? Can you give me a example, how to retrieve data from a external database with a sql query with db read?
Or: when a i selected the table in the external database tab of db read, where can i select the fields, conditions etc.?
Thanks for your help!

Mazin
GreyHead 21 Nov, 2014
Hi Mazin,

Max has already answered that I think. Check the Dynamic DropDown demo form.

Bob

PS I was wrong, the latest version of CFv5 does have the External Database tab in the DB Read action.
Max_admin 25 Nov, 2014
Hi Mazin,

After you enable the action and select the table, the action should read all the table records, unless you add some conditions to the "Conditions" box.

Now the data should be available in the data array (you can check this using a debugger action), you can use it anyway you want, in your case, you need to json_encode the list of data you want to return!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.