Hello,
I’m trying to create dependant dropdown without using database tables. And the values will be loaded in the function and returned.In the view, i have set those values in the dropdown. Now the problem is i want to make the sencond dropdown list dependant based on the the value selected in the first drop down.
Here is what i have done till now.
In my Model :
public function getDistrictList(){
return array(
array('key'=>'GLB', 'value'=>'Gulbarga'),
array('key'=>'YG', 'value'=>'Yadgir'),
array('key'=>'BNG', 'value'=>'Bangalore'),
array('key'=>'MSR', 'value'=>'Mysore'),
);
}
public function getTalukList(){
return array(
array('key'=>'BN', 'value'=>'Bangalore North'),
array('key'=>'BS', 'value'=>'Bangalore South'),
array('key'=>'BE', 'value'=>'Bangalore East'),
array('key'=>'ANK', 'value'=>'Anekal'),
array('key'=>'GLB', 'value'=>'Gulbarga'),
array('key'=>'YG', 'value'=>'Yadgir'),
array('key'=>'SDM', 'value'=>'Sedam'),
array('key'=>'CHT', 'value'=>'Chittapur'),
array('key'=>'CHN', 'value'=>'Chincholi'),
array('key'=>'JVG', 'value'=>'Jevargi'),
array('key'=>'MSR', 'value'=>'Mysore'),
);
}
In my view :
<div class="row">
<label for="district"><?php echo CHtml::encode($model->getAttributeLabel('district')); ?></label>
<?php $list = CHtml::listData(Inquiries::model()->getDistrictList(), 'key', 'value'); ?>
<?php echo $form->dropDownList($model, 'district', $list, array('empty'=>'(Select a District)')); ?>
</div>
<div class="row">
<label for="taluq"><?php echo CHtml::encode($model->getAttributeLabel('taluq')); ?></label>
<?php $list = CHtml::listData(Inquiries::model()->getTalukList(), 'key', 'value'); ?>
<?php echo $form->dropDownList($model, 'taluq', $list, array('empty'=>'(Select a Taluk)')); ?>
</div>
Please help me.