nazum
(Nornholdj)
March 22, 2011, 10:05am
1
Hi,
Is there an easy way to implement AJAX into a form to create say a cascading drop down list where what you choose in the first list will limit what you can see in the next and so forth. I’m using the CActiveForms created by gii and I was wondering if I could keep using those.
Thanks,
-Nazum
gusnips
(Gustavo)
March 22, 2011, 10:22am
2
Yes, you can keep on using
Add selectors(id,class) using htmlOptions to the select boxes so you can then use js normally and do what you want
something like
//php code
$form->dropDownList($model,'attributeName',array(1=>'yes',2=>'no'),array('id'=>'mySelect'));
$form->dropDownList($model,'otherAttributeName',array(1=>'so yes ?',2=>'so no ?'),array('id'=>'myOtherSelect'));
//js code
$("#mySelect").change(function(){
value=$(this).find('option:selected').val();
$("#myOtherSelect").find('option[value!='+value+']').hide();
//or to select
$("#myOtherSelect").val(value);
});
something like that
nazum
(Nornholdj)
March 22, 2011, 11:06am
3
I was actually thinking along the lines of populating the second list but I get the idea. Thanks!!