Dependent dropdown lists, second one is empty

Hi, I have two dropdown lists which should display campus and selected campus’ buildings. When I choose campus, second dropdown isn’t changed. However, when I check it with Firebug, response seems ok.


	<div class="row">

		<?php echo $form->labelEx($model, 'locationId'); ?>

		<?php echo $form->dropDownList(Location::model(),'campus', CHtml::listData(Location::model()->findAll(), 'campus', 'campus'),


					'empty' =>'--please select--',	

					'ajax' => array(

					'type'=>'POST', //request type

					'url'=>CController::createUrl('dynamicBuildings'), //url to call.

					//Style: CController::createUrl('currentController/methodToCall')

					'update'=>'#building', //selector to update

					//'data'=>'js:javascript statement' 

					//leave out the data key to pass all form values through




		<?php echo $form->error(Location::model(),'campus'); ?>



	<div class="row">

		<?php echo $form->labelEx(Location::model(), 'building'); ?>

		<?php echo $form->dropDownList(Location::model(),'building', array(), array('empty' =>'--please select campus first--')); ?>

		<?php echo $form->error(Location::model(),'building'); ?>



	public function actionDynamicBuildings()


		//please enter current controller name because yii send multi dim array

		//$campus = $_POST['Location'];


				array(':campus'=> $_POST['Location']['campus']));


		if($data == null){

			echo CHtml::tag('option',

					array('empty'),CHtml::encode('--please select campus first--'),true);



			echo CHtml::tag('option',

					array('empty'),CHtml::encode('--please select--'),true);


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


			echo CHtml::tag('option',




Firebug response is in this type: "<option 0="empty">–please select–</option><option value="BCC">BCC</option><option value="EB">EB</option><option value="G">G</option><option value="Other…">Other…</option>". I want second dropdown to show exactly these values but it shows only "–please select campus first–". What can be the problem?



sorry havent catch you up on irc. :)

i think this portion:

‘update’=>’#building’, //selector to update

has to be set to the correct element id. probably that building dropdown list has an id in the form YourModel_attribute (i am guessing it will be Location_building in your case). :)


Thank you VERY much. That solved the problem :)