cake php, how to populate a drop down selection based on another drop down selection?
I have a table something like this:
id test attr dim
1 test1 a1 d1
2 test2 a2 d2
3 test3 a1 d3
4 test3 a1 d2
I am creating a drop down field that shows the 开发者_运维技巧attr
as having only two options a1 and a2
. Based on a selection of either a1
or a2
i would like to do is something like:
if (a1 is selected){$a == a1} else {$a == a2}
$test = mysql_query("SELECT dim FROM xxx WHERE attr = $a")
and fill up the second drop down with the results from that query that could be d1
, d2
or d3
and so on, on multiple drop down lists if I need to.
I know how to do this in regular php but not sure how to do it in CakePHP.
Any ideas?
Edit: I'm not sure if i need to use any ajax, this should be working without it
You can do with help of ajax->observefield
eg:
$options = array('url' => 'getcounties', 'update' => 'ExampleCountyI
$ajax->observeField('ExampleStateId', $options);
UPDATED
observeField is not more available in CakePHP js helper here it's equivalent way to the same for newer CakePHP version >= 2.x
精彩评论