蛋糕php,如何填充一个下拉选择基于另一个下拉选择? [英] cake php, how to populate a drop down selection based on another drop down selection?

查看:95
本文介绍了蛋糕php,如何填充一个下拉选择基于另一个下拉选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的表:

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

我创建一个下拉字段,显示 attr 只有两个选项 a1和a2 。基于选择 a1 a2 我想做的是:

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")

并填写第二个下拉菜单该查询可以是 d1 d2 d3

and fill up the second drop down with the results from that query that could be d1, d2 or d3

等等。

我知道如何做到这一点。

I know how to do this in regular php but not sure how to do it in CakePHP.

任何想法?

编辑:我不知道如果我需要使用任何ajax,这应该没有它工作

Edit: I'm not sure if i need to use any ajax, this should be working without it

推荐答案

通过 ajax-> observefield

的帮助执行操作:eg:

eg:

$options = array('url' => 'getcounties', 'update' => 'ExampleCountyI
$ajax->observeField('ExampleStateId', $options);

UPDATED

observeField在CakePHP js助手中不可用此处对于较新的 CakePHP version> = 2.x

observeField is not more available in CakePHP js helper here it's equivalent way to the same for newer CakePHP version >= 2.x

这篇关于蛋糕php,如何填充一个下拉选择基于另一个下拉选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆