Depedant drop downlist

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:


echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),


'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()



	                  array(':parent_id'=>(int) $_POST['country_id']));



	    foreach($data as $value=>$name)


	        echo CHtml::tag('option',




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>


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 ?


You are better off using this extension:


So you dont need to worry about all the logic in this.

Thanks sir for this quick response, i’ll read those tutorials now :)

Now the ajax call work and im able to call my action


, but i have an other error now which is: Undefined index: country_id.

Do you have an idea why i have this error ? because in the dopdwonlist i have the "country_id" index !

In my action i added


, and it’s empty because it return

array(0) {}


Check firebug, Im not familiar with the extensions, they might be using GET to send the parameters, Undefined index: country_id. is clearly a problem in your controller’s action