populate two dropdowns on selecting on dropdown

i am trying to fill two dropdowns on selecting from one dropdown.

i tried this code…

in the form…


  <?    $company = new CDbCriteria; 

              $company->order = 'company_name ASC';?>

		<?php echo $form->dropDownList($model, 'company_id',CHtml::listData(Company::model()->findAll($company),'company_id','company_name'), array(

                            'ajax' => array(

                            'type' => 'POST',

							 'dataType'=>'json',

                      'data'=>array('company_id'=>'js: $(this).val()'),

                            'url' => CController::createUrl('loanDetails/employee'),

                           // 'update' => '#param_id',

							'success'=>'function(data) {

    $("#employee_id").html(data.dropDownA);

    $("#surety").html(data.dropDownB);

 }',

                      )       

                  ) ); ?>

                <div class="row">

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

		<?php //echo $form->dropDownList($model, 'employee_id', array('prompt' => 'Select employee') ); ?>

        <?php echo $form->textField($model,'employee_id'); ?>

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

	</div>

                




<div class="row">

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

	<?php echo $form->dropDownList($model, 'surety', array('prompt' => 'Select employee') ); ?>

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

	</div>



on selecting company i want both employee dropdown and surety dropdown to be filled.

here’s ma function in the controller…


public function actionEmployee()

{

		echo $company_id = $_POST['company_id']; 

		 // echo $company_id=1;

		//exit;

			$dataA=Employee::model()->findAll('company_id=:company_id',array(':company_id'=>$company_id));

			

			 $dataA=CHtml::listData($dataA,'employee_id','employee_name'); 

			 

			

if(count($dataA)==0)

			$dataA=array('None');

			 $dropDownA='';

			  $dropDownB='';

			

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

 $dropDownA .= CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);


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

  $dropDownB .= CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);


$hello='how are you';

// return data (JSON formatted)

echo $array=CJSON::encode(array(

  'dropDownA'=>$dropDownA,

  'dropDownB'=>$dropDownB

));		

can anyone tel me where m goin wrong?

i followed this wikiMy link





	$("#MODEL_NAME_employee_id").html(data.dropDownA);

    $("#MODEL_NAME_surety").html(data.dropDownB);




I have tried that too… but it does not work.

eg my model is:LoanDetails

$("#LoanDetails_employee_id").html(data.dropDownA);

&#036;(&quot;#LoanDetails_surety&quot;).html(data.dropDownB);

do i need to enable anything for JSON to work?

To get the proper label use activeId() - http://www.yiiframework.com/doc/api/1.1/CHtml#activeId-detail

Did you get it to work for one dropdown?

Use firebug to debug a bit… check if the ajax call is made… if the right data is returned… check that the right fields are updated…