Hello,
I’ve searching through the internet for about 4 days but I still cannot figure out, my problem is any idea how to make two dropdownlist depend on one dropdownlist? I manage to do one to one. Hopefully, someone can answer my question. I’m new in ajax and yii. Any link for reference is appreciate
view
<div class="row">
<!-- LOCATION -->
<?php echo $form->labelEx($model,'locationid'); ?>
<?php echo $form->dropDownList($model,'locationid',
CHtml::listData(location::model()->findAllbysql('select id,CONCAT(description, " (", code ,")") as description from tbllocation'), 'id', 'description'),
array(
'ajax'=>array(
'type'=>'POST',
'url'=> $ajaxUrl,
'update'=>
'update'=>'#'.CHtml::activeId($model,'divisionid'),
'beforeSend'=>'function(){
$("#fieldmaster_divisionid").find("option").remove();
$("#fieldmaster_subdivisionid").find("option").remove();
}'
),'prompt'=>'<please select>'
/* 'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('fieldmaster/Selectdos3'),
'update'=>'#'.CHtml::activeId($model,'blockid'),
),*/
)
); ?>
<?php echo $form->error($model,'locationid'); ?>
</div>
<?php echo $form->labelEx($model,'blockid'); ?>
<?php echo $form->dropDownList($model,'blockid',array()); ?>
<?php echo $form->error($model,'blockid'); ?>
<div class="row">
<?php echo $form->labelEx($model,'divisionid'); ?>
<?php echo $form->dropDownList($model,'divisionid',array()); ?>
<?php echo $form->error($model,'divisionid'); ?>
</div>
controller
public function actionSelectdos()
{
$id_uno = $_POST['fieldmaster']['locationid'];
$lista = division::model()->findAll('locationid = :id_uno', array(':id_uno'=>$id_uno));
$lista = CHtml::listData($lista, 'id', 'description');
echo "<option value = '0'><please select></option>";
foreach($lista as $valor => $description){
echo CHtml::tag('option', array('value'=>$valor),CHtml::encode($description), true);
}
}