Hello friends…
Am using Dependent dropdownlist in my form. the thing is 1.department 2.designation.
If we select the department field the designation want to be changed. Am using some code but i got error.
Plz take a look at my code and help me out without error..
in my _form.php department dropdownlist
<?php echo $form->dropDownList($model,'department',CHtml::listData(Department::model()->findAll(),'id','department'), array(
'prompt'=>'Select department',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('User/designation'),
'update'=>'#User_designation',
'dataType'=>'json',
'data'=>array('id'=>'js:this.value'),
'success'=>'function(data) {
alert("hi");
//$("#User_designation").html(data.dropDownDesignation);
}',
))); ?>
in my _form.php designation dropdownlist
<?php $desg = CHtml::listData( designation::model()->findAll(array('order' => 'designation')), 'desig_id', 'designation');
echo $form->dropDownList($model, 'designation', $desg, array(
'prompt'=>'Select designation',
// 'ajax' => array(
//'type' => 'POST', //request type
//'url' => CController::createUrl('ajax/getCities'), //url to call.
//'update' => '#Address_city_id', //selector to update
// '//data' => array('state_id' => 'js:this.value'),
));?>
Usercontroller.php
public function actiondesignation()
{
//states
$data = Designation::model()->findAll('dept_id=:dept_id', array(':dept_id'=>(int) $_POST['department']));
$data = CHtml::listData($data,'desig_id','designation');
$dropDownDesignation= "<option value=''>Select</option>";
foreach($data as $value=>$name)
$dropDownDesignation .= CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
echo CJSON::encode(array('dropDownDesignation'=>$dropDownDesignation));
//echo $dropDownStates;
}
help me out and thanks…