Forums

double dropdown / javascript value

nataliaalex 06 Sep, 2014
Hello,

I would like to build a form with double dropdown elements. The values of the second dropdown will depend of the values of the first one, all of them stored in my joomla database. I don’t want to use DB Read/DB Load actions, just SQL statements, because there will be many nested “where” criteria.

Having read many relevant posts in this forum, I have successfully:
- populated my first dropdown
- created the following simple Load JS action inside the “OnLoad” event, which get the id value, when a user select a value in the first dropdown:

jQuery(document).ready(function($){
$("#item").change(function() {
my_selected_item=$("#item").val();
});
});

I have just limited javascript knowledge, and what I am wondering is how to pass the my_selected_item value (taken from the aforementioned Load JS action), in the custom code of another event.

The custom code will have the SQL statement which will populate my second dropdown and the my_selected_item value will be used in its “where” criteria.

The event in which the above custom code will be used is based on your example "demo-dynamic-dropdown" (included in ChronoForms Component v5)

I will appreciate very much your help
Thank you/Alexandra
GreyHead 06 Sep, 2014
Hi Alexandra,

The simple answer to this is to let ChronoForms handle the Ajax end of this and then you can add your custom MySQL queries in the 'ajax' form event. That removes the need for you to handle the JavaScript.

Bob
nataliaalex 06 Sep, 2014
Hello Bob,

Thank you for your quick reply.

Could you please be more specific?

What exactly I have to do? How may I let CFv5 handle the Ajax (I didn't create any ajax code, I don't know about it!!!). I have just created an event like the "On load_club" on the example "demo-dynamic-dropdown" (included in ChronoForms Component v5).

In this event I have put a "custom code" action with my SQL statement inside. What I need is to establish my "where" criteria in my SQL statement. This is why i have asked how to pass the value from the Load JS action.

Do you have the time and the will to help me step by step to resolve the issue?

Have a nice day
Alexandra
GreyHead 06 Sep, 2014
Hi Alexandra,

Please see this FAQ which I wrote this afternoon, you can replace the DB Read with a custom query if you prefer.

Bob
nataliaalex 08 Sep, 2014
Hi Bob,

thank you very much for your FAQ. It's more clear now.
I have used custom codes instead of DB Read actions to read my tables and populate both dropdowns.

It works ok, except the "Please Select a State...." in the second dropdown element.

I have put the following texts in the Empty Option of the dropdowns:

"Please Select a Country" in the first dropdown and
"Please Select a State" in the second dropdown

However, the text in the second dropdown remains empty (the text "Please Select a State" it's not displayed). Is it possible to display the text in both dropdowns, at the same time WHEN the form is loaded and make the second one displayed as inactive (i.e. with a gray color) until the user make its selection in the first dropdown?

I will appreciate your help
Many thanks
Alexandra
nataliaalex 14 Sep, 2014
Hello,

could anyone reply to my question please (please see my previous post)?

Is it possible to display the text in both dropdowns, at the same time WHEN the form is loaded and make the second one displayed as inactive, until the user make its selection in the first dropdown?

I will appreciate your help
Many thanks
Alexandra
GreyHead 14 Sep, 2014
Hi Alexandra,

If you put a single = into the Options box of the second drop-down then what ever you have in the Empty Option box will display.

Bob
nataliaalex 15 Sep, 2014
Hello Bob,

Perfect. It works.

Thank you so much

/Alexandra
This topic is locked and no more replies can be posted.