Hi Guys,
I have struggled with this problem for a couple of days and I just seem to get it right. I am trying to create one drop down list that is dependent on another. I have followed through some of the examples given in a google search but they don’t seem to work either.
Here is the code in my view file
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'play_form2',
'enableAjaxValidation'=>true,
));
$genClass = makesModels::model();
$criteria = "ParentID = 0";
$genData = Chtml::listData($genClass->findAll($criteria), 'ID', 'Description');
$options = array(
'id' => 'ParentID',
'ajax' => array('type'=>'POST'
, 'url'=>DealsController::createUrl('deals/dynamicModels')
, 'update'=>'#'.CHtml::activeId($model, 'ModelID')
)
);
echo CHtml::dropDownList('ID', '', $genData, $options);
echo $form->dropDownList($model, 'ModelID', array());
$this->endWidget();
?>
And Controller
public function actionDynamicmodels() {
$param_parent =$_POST['ParentID'];
$criteria = "ParentID=$param_parent";
$data = makesModels::model()->findAll();
$data = CHtml::listData($data, 'ID', 'Description');
foreach($data as $value) {
echo CHtml::tag('option',array('value'=>$value->ID,CHtml::encode($value->Description) , true) );
}
}
Any pointers are greatly appreciated