Yii Depending Dropdownlist with AJAX

Halo semua ,

Saya mau bertanya soal Yii Dropdownlist ,

saya ingin ketika pilih Customer, Dropdown Sales langsung terpilih (yang terhubung dengan Customer) , bagaimana cara nya ? berikut saya punya table :


  • sales_id

  • customer_id


  • customer_id

  • customer_name


  • sales_id

  • sales_name

mohon bantuan’nya , berikan contoh script MVC nya , terimakasih master … :)

dependentController.php file put this action code 

 public function actiongetstatecity()



	$data=State::model()->findAll(array('condition'=>'country_id='.(int) $_REQUEST['City']['country_id']));



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


                echo CHtml::tag('option',




this is my city.php file in which i want dependent drop down …as iam selecting country based on that u can select state…and then u can type ur city name…

refer this code for ur code…

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


			echo $form->dropDownList($model,'country_id', Country :: items(),


			'prompt' => 'Select Country',

			'ajax' => array(



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





			?><span class="status">&nbsp;</span>

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


	<div class="row">

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




				echo $form->dropDownList($model,'state_id', CHtml::listData(State::model()->findAll(array('condition'=>'state_id='.$model->state_id)), 'state_id', 'state_name'));


				echo $form->dropDownList($model,'state_id',array('empty' => 'Select State')); ?><span class="status">&nbsp;</span>

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


	<div class="row">

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

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

		<?php echo $form->textField($model,'city_name',array('size'=>30,'maxlength'=>60)); ?><span class="status">&nbsp;</span>


try this in your code.

hope it will helpful to you…if any query then let me know.