Loading data in forms


#1

I require to display the data in dropdown field 2 based upon the value selected in dropdown 1.
Is there any option to do that based upon the changes


#2

I was unable to find any built-in method for that in cakePHP, you can use simple Jquery function to achieve that functionality.

Here is the code

$("#dropDown-1-id").change(function(){

$someVariable = $("#dropDown-1-d option:selected").val();
$("#dropDown-2-id option[value='"+$someVariable+"']").attr("selected","selected");

});

In my above example, I am assuming that the values I want to be selected have same ‘value’ attribute. for e.g.
if value=“1” is selected from 1st dropdown then select value=“1” for 2nd dropdown as well.

Change the selection criteria as per your requirement.


#3

Thank you, I require the data to be filled from the database. How to do it


#4

dereuromark has some nice examples:
http://sandbox.dereuromark.de/sandbox/ajax-examples/chained-dropdowns

its work like this: $("#combobox1").change() do a ajax request passing the selected value for Controller function that do database search and return a json/html data to fill the combobox2

for code search in github: