Hi all,
Please i have been having challenges getting this done.
I have a dropdown A (A- list data from a model ‘CompetencyType’. Each competency type has sub category) .
Now my problem is that, I want to populate dropdown B(with Sub_category) using the selected item from dropdownA.
Please what am i doing wrong? I have tried all i could but seems not working.
This is my View
<div class="row">
<?php echo $form->labelEx($model,'competency_type'); ?>
<?php echo $form->dropDownList($model,'competency_type', CHtml::listData(competencyType::model()->findAll(array('order'=>'competency_type')), 'competency_type', 'competency_type'),
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('CompetencyManager/GetType'),
'update'=>'#'.CHtml::activeId($model,'sub_name')))); ?>
<?php echo $form->error($model,'competency_type'); ?>
</div>
<?php echo CHtml::dropDownList(‘sub_name’,’’, array() ); ?>
This is my Controller
public function actionGetType()
{
$competency_type = $_POST['CompetencyManager']['competency_type'];
$data=CompetencyType::model()->findAll('competency_type=:competency_type',
array(':competency_type'=> $competency_type));
$data=CHtml::listData($data,'id','sub_name');
foreach($data as $value=>$subname)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($subname),true);
}
}