Know How To Build Auto Complete Text Box Dependent On Dropdown

1st : go to view/_form.php where you want your Drop down .


2nd : [/b]copy past the following code with your won model names

// Our Drop Down

	<div class="row">

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



		$products = CHtml::listData(product::model()->findAll(),'product_id','product_name');

            $options = array(

                'empty' => '--Select a Product--',

                'ajax' => array('type'=>'POST'

                                , 'url'=>CController::createUrl('SalesReport/GetPrice')

								,  'data'=> array('product_name'=>'js:this.value')


                               , 'update'=>'#price_id' 



 //selector to update



           //echo $form->field($model, 'product_name')->dropDownList('product_name', '', $products, $options);

           //echo CHtml::dropDownList('product_name', '', $products, $options);

            echo $form->dropDownList($model,'product_name',CHtml::listData(product::model()->findAll(),'product_id','product_name'), $options,array('onchange'=>'get_amount(this);'));


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


// Our text field 

	<div class="row" >

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

		<div id="price_id" >

		<?php echo $form->textField($model,'product_sale_rate',array('id'=>'sale_rate','onchange'=>'get_amount(this);')); ?>


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


3rd : Now go to your controller Copy past the code with your won query

	  public function actionGetPrice()



         $product_id = (int)$_POST['product_name'];

		 //echo $product_id;


         $data = Yii::app()->db->createCommand()->



          where(array('like', 'product_id',$product_id))->



		  $a= array_shift($data);

		  $result= array_shift($a);




		 echo CHtml::activetextField($model,'product_sale_rate', array('value' => $result,'onkeypress'=>'get_amount(this);','id'=>'sale_rate'));





4th : Update your accessRules in controller

public function accessRules()


		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions




			array('allow', // allow authenticated user to perform 'create' and 'update' actions




			array('allow', // allow admin user to perform 'admin' and 'delete' actions




			array('deny',  // deny all users





Ok . You Done .

You can easily do with CJuiAutoComplete, visit this links and get idea.

links -