Hi mastermunj, with the example given in dependent drop down I wasn’t able to make it work. I just wanted to make it work first, could help me in my code, here it is:
In view:
echo CHtml::dropDownList(‘country_id’,’’, array(1=>‘USA’,2=>‘France’,3=>‘Japan’),
array(
‘ajax’ => array(
‘type’=>‘POST’, //request type
‘url’=>CController::createUrl(‘useraccounts/dynamiccities’), //url to call.
//Style: CController::createUrl(‘currentController/methodToCall’)
‘update’=>’#city_id’, //selector to update
//‘data’=>‘js:javascript statement’
//leave out the data key to pass all form values through
)));
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList(‘city_id’,’’, array());
In controller
array(‘allow’, // allow authenticated user to perform ‘create’ and ‘update’ actions
'actions'=>array('create','update','dynamiccities'),
'users'=>array('@'),
),
public function actionDynamiccities()
{
//please enter current controller name because yii send multi dim array
$data=Location::model()->findAll('parent_id=:parent_id',
array(':parent_id'=>(int) $_POST['Useraccounts']['country_id']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}