Hi guys,
I’m trying to use an depedant dropdownlist using the yii approach and following the tutorial for this purpose, but the “onchange” attribute is never created!!. I’m using the 1.1.4 yii version
This is my code in the view:
<?php
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('country/Dynamiccities'), //url to call.
'update'=>'#city_id', //selector to update
)));
echo CHtml::dropDownList('city_id','', CHtml::listData(Cities::model()->findAll(),'cities_id','name'));
?>
In my country controller:
public function actionDynamiccities()
{
$data=City::model()->findAll('parent_id=:parent_id',
array(':parent_id'=>(int) $_POST['country_id']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
But the code generate in my view is :
<select id="country_id" name="country_id">
<option value="1">USA</option>
<option value="2">France</option>
<option value="3">Japan</option>
</select>
But i should have the "onchange" attribute with something like : onchange="country/dynamiccities" !
Do you have an idea why i don’t have the good code in my view ?
Thanks