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 :

"invoice"

  • sales_id

  • customer_id

"customer"

  • customer_id

  • customer_name

"sales"

  • 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']));

                  	

            $data=CHtml::listData($data,'state_id','state_name');

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

            {

                echo CHtml::tag('option',

                        array('value'=>$value),CHtml::encode($name),true);

            }

  }



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'); ?>

	<?php

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

			array(

			'prompt' => 'Select Country',

			'ajax' => array(

			'type'=>'POST', 

			'url'=>CController::createUrl('dependent/getstatecity'), 

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

			 

			),'tabindex'=>21));

			

			 

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

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

	</div>

	<div class="row">

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

		<?php 

		

			if(isset($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'));

			else

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

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

	</div>

	<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>

	</div>







try this in your code.

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

Thanks