Dependent dropdown list is not set in updation form

Hi friends,

I’m working with the drop down list and working fine while creation and deletion, but my problem is during the updating of that particular form…

I’m having country_id and state_id, when I’m clicking updating button the country_id field loads automatically, but state_id is not set and while submitting the form that field shows error and I need to re choose the country_id field and state_id field for every other field updating also it really create irritation for updating…

If any suggestion to keep that drop down field always set based on database values…

This is my code…

Creating/Updating form…

<div class="row">

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

	<?php echo $form->dropDownList($model,'country_id',






		'update'=>'#CityMaster_state_id','data'=>array('id'=>'js:this.value')))); ?>

		<?php echo $form->error($model,'country_id'); ?>


<div class="row">

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

	<?php echo CHtml::dropDownList('CityMaster[state_id]','',array(),

			array('empty'=>'Select')); ?>

	<?php echo $form->error($model,'state_id'); ?>



public function actionDynamicstate()


	$model1=new CityMaster;

	$data=StateMaster::model()->findAll('country_id=:country_id AND status=:status',



	echo CHtml::activeDropDownList($model1,'state_id',$data1,array('empty'=>'-- Select --'));


I try to used separate form for the creation(_form) & updating(_updating) also, but it’s not working…

Thanks in advance friends…


It seems that you dont have provided a 3rd param in dropdownlist to show a selected value.

check This link For information.

Checkout this link

Just need adjusted with your model

Thanks for your tutorial links and I got output exactly what I want by refer the link… :P

Hey Sathishkumar could you share the solution in the thread …i tried to follow the two links but could not find a perfect solution…Await your response.

Thanks in advance !!!!


please share the solution

@Sandeep can u please post your code…