Dynamic Double DropDown

rafrev 09 Feb, 2016
Hi to all,
I have one problem with a dynamic double dropdown in my form.
I follow your example at this
Something is wrong but i don't understand where or what. Can You help me?

I have 2 dropdown fields.
The first with this values:
1=area 1
2=area 2
3=area 3

The second should be populated dynamically from a table in relation with the value of the first dropdown.
this is the desigenr view:

My db table have these fields:
ID_AT = integer primary key
ID_Area = integer (join with the values of dropdown1)
Description = varchar

These are the values of DB read tab:

Enabled : Yes
Table name : cri_table_activity
Multi read : Yes
Enable Model ID : Yes
Model ID : Data
Fields : ID_AT, Description

Conditions :
return array( 'ID_Area' => $form->data['dropdown1'] );

This is PHP code in the custom code tab:

//dichiarazione variabile
$options = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$options[] = 'Please select a category';
} else {
foreach ( $form->data['Data'] as $d ) {
echo json_encode($options);

This is the front end form without selections in dropdown1:

This is the front end form with selection Area 1 in dropdown1:

Where I am wrong?
Thank in advamce for your help.
GreyHead 10 Feb, 2016
Hi Raffaele,

Please remove the space in the Fields list: Fields : ID_AT,Description

If that does't solve it you should be able to see what is being returned by the Ajax query using the Network tab in your browser Web Developer tools.

rafrev 10 Feb, 2016
Hello Bob, with your help I resolve my problems.

All is ok. The form run normaly!!!

Thank you very much.

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