【发布时间】:2014-05-19 20:19:35
【问题描述】:
在我的 Zend 表单中,我有 2 个选择框,每个框选择同一张表中的不同列。 如何使这两个项目相互依赖:如果选择了 box1 中的值,则选择了 box2 中的匹配值,如果我选择了 box2 中的值,则选择了 box1 中的匹配值。 这样我可以选择在任一列上进行选择。
我的桌子:
标识码说明
1 个苹果
2 B 香蕉
我的表单元素:
$objcode = new Zend_Form_Element_Select( 'code');
$objcode
->setRequired(false)
->setAttrib('id','code');
->...more attributes to cleanup input
$this->addElement($objcode );
$objdescription = new Zend_Form_Element_Select( 'description');
$objdescription
->setRequired(true)
->setAttrib('id','description');
->...more attributes to cleanup input
$this->addElement($objdescription);
查看:
<td>Box1</td>
<td><?php echo $this->objForm->code?></td>
<td>Box2</td>
<td><?php echo $this->objForm->description?></td>
因此,如果我在 box1 中选择 B,则 box2 中的选定值应更改为 Bananas。如果我在 box2 中选择 Apples,则 box1 中的值应更改为 A。
我使用 jQuery 找到了this link,但没有成功,这只是一种方法(框 2 依赖于框 1,但框 1 不依赖于框 2)。 我确定我需要 JQuery on change 事件来处理这个问题,但我不确定是否将 jQuery 放在表单或视图中以及如何?
我尝试在表单元素代码中添加此属性:
->setAttrib('onChange','javascript: OnChangeCode();')
并在视图中添加:
function OnChangeCode()
{
JQuery("#code").change(function () {
JQuery("#description")[0].selectedIndex = JQuery(this)[0].selectedIndex;
});
}
但是没有结果。
【问题讨论】:
标签: jquery zend-framework select dropdownbox