Forums

[Solved] Need help with several dropdown fields AJAX and PHP

brostalski 18 Jan, 2013
Hi!

I have a form with 5 dropdowns and some other fields.

- dropdown(1)+(2) are dynamic and filled from database
- dropdown(4) have fixed values
- dropdown(3)+(5) filled with DB Multi Record Loader

All dropdowns have value "Please select..." as default.

If dropdown(2) is changed, dropdown(3) loads the data with selected value of dropdown(2). If dropdown(4) is changed, dropdown(5) loads the data with selected value of dropdown(4).
If i change dropdown(2), all next dropdowns reset to default and so on...

All works great but now, i need help at the DB Multi Record Loader for dropdown(5).
To filter & order the output data i set the following in the DB Multi Record Loader -> Advanced Tab -> WHERE statement:

`Altersklasse_Geschlecht` = <?php echo $form->data['geschlecht']; ?> ORDER BY `Altersklasse_Kurz` ASC


Now i need a second filter with the selected value from dropdown(3)!

If i add a second filter to the WHERE statement:
`Altersklasse_Geschlecht` = <?php echo $form->data['geschlecht']; ?> AND `Altersklasse_Wildtyp` = <?php echo $form->data['wildtyp']; ?> ORDER BY `Altersklasse_Kurz` ASC

the dropdown is empty!

The ModelID for dropdown(3) is 'wildtyp'. Can i get the dynamic data value in DB Multi Record Loader of dropdown(5)? The output data must be filterd by 2 values (wildtyp and geschlecht).

Greetz
brostalski
brostalski 08 Feb, 2013
Hi!

Now, i find out why the dropbox(5) is still empty. $form->data['wildtyp'] is empty.

How can i get the selected value of an dynamic dropdown (use Ajax YES, Event with "DB Multi Record Loader" to get the data) to the WHERE statement of the second dynamic dropdown (use Ajax too, Event with "DB Multi Record Loader")?

Thanks!
GreyHead 08 Feb, 2013
Hi brostalski ,

If you are doing this using Ajax then you will need to pass both values in the URL that calls the Ajax function. I don't think that the Dynamic Drop-down action supports this, so the Ajax request would need to be hand-coded.

I hope that I'm answering the correct question here.

Bob
brostalski 11 Feb, 2013
Hi Bob,

not at the "Dynamic Dropdown" but at the "DB Multi Record Loader" there is an option "Request Param".
Can i set here the values for the Ajax Call? I need 2 values!

greetz
brostalski
brostalski 12 Feb, 2013
Hi all!

I delete the "dynamic dropdown" and add "Load JS" with an Ajax Call to the OnLoad Action.
Problem is solved!

Thanks Bob!
MichielStr 09 Mar, 2013
Hi Brostalski,

Would you mind sharing your code? I am trying to do the same and would like to understand how you solved it.

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