Hi! I’ve got a problem, I was hoping if you could give me some insight. I have 2 dropdown boxes. I wanted to filter the contents of the 2nd dropdown box according to what the user will select on the 1st one. obviously the fields would come from the database. The 1st dropdown works fine, but when i select from it nothing happens on the other one.
I have 2 tables here:
ps_ref_region(table name)
region_ref_id(pk)
region_name
ps_ref_province(table name)
province_ref_id(pk)
region_ref_id(fk)
province_name
_form.php
<td> <?php echo $form->labelEx($model,'Region'); ?></td>
<td> <?php
echo $form->dropDownList($model,'region_reference_id',CHtml::listData(Region::model()->findAll(),'region_reference_id','region_name'),
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Institution/address'),
'update' => 'province_reference_id'
)
)
);
?>
</td>
<?php echo $form->error($model,'region_reference_id'); ?>
<tr>
<td> <?php echo $form->labelEx($model,'Province'); ?></td>
<td><?php echo $form->dropDownList($model,'province_reference_id',array());?></td>
<?php echo $form->error($model,'province_reference_id'); ?>
</tr>
institutionController.php
public function actionAddress() {
$region_id = $_POST['Institution']['region_reference_id'];
$data=Province::model()->findAll('region_reference_id=:region_reference_id',
array(':region_reference_id'=> $region_id));
$data=CHtml::listData($data,'province_reference_id','province_name');
foreach($data as $value=>$subcategory) {
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($subcategory),true);
}
}