dependent dropdown not working

Hello,

I try to use dependent dropdown but it’s not working ,it shows the correct value but it does not store the value selected it only saves the default database value. here is my view and controller. Can you please help me?

view---------------------------------------------------

<div class="row">     


   <?php echo $form->labelEx($model,'id_client',array('label'=>'Cliente'));


$client = new CDbCriteria;


 //   $client->condition = 'status = 1';


$client->order = 'client ASC';


echo $form->dropDownList($model,'id_client',CHtml::listData(Client::model()->findAll($client),'id_client','client'),


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


       // 'dataType'=>'json',


        'url' => CController::createUrl('hour/loadprojects2'), 


       'update'=>'#id_project',


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

// ‘success’=>‘function(data) { $("#id_project").html(data.id_project)} }’,

        ),'prompt' => 'Seleccione un Cliente'


)


);


    


echo $form->error($model,'id_client'); ?>


</div>


       





<div class="row">


<?php //echo $form->labelEx($model,'id_project',array('label'=>'Proyecto'))?>


               





<?php // echo $data= CHtml::dropDownList('id_project','project',array('empty'=>'----PROYECTO-----'));?>

<?php echo "Create Hours for the user id : ". $model->id_project;?>

<?php echo CHtml::dropDownList(‘id_project’,‘project’, array(‘empty’=>’----PROYECTO-----’)); ?>

<?php // echo $form->dropDownList($model,‘id_project’,CHtml::listData(Project::model()->findAll(), ‘id_project’, ‘project’)); ?>

<?php // echo $form->dropDownList($model, ‘id_project’, ($model->isNewRecord) ? array() : CHtml::listData(Project::model()->findAll(), ‘id_project’, ‘project’)); ?>

    &lt;/div&gt;

controller-----------------------------------------------------------------

   public function actionloadprojects1()

{

$values = $_POST[‘Hour’];

$keyword = $values[‘id_client’];

$data=Project::model()->findAllBySql(

"select * from project where id_client

=:keyword and status = 1 order by project asc",

// Aquí buscamos los diferentes organismos que pertenecen al tipo elegido

array(’:keyword’=>$keyword));

$data = CHtml::listData($data,‘id_project’,‘project’);

//echo CHtml::tag(‘option’,array(‘value’ => ‘’),’’,true);

$dropdown=’’;

       foreach(&#036;data as &#036;id =&gt; &#036;value)


       {


         &#036;dropDown .= CHtml::tag('option',array('value' =&gt; &#036;id),CHtml::encode(&#036;value),true);


             


       }





 echo CJSON::encode(array(





              'id_project'=&gt;&#036;dropDown,


            ));

}

thanks in advance

Hi Ge0rge,

Welcome to the forum.

Please use the code tag so your posts are easily readable (thx). Please explain why you are initiating ajax request to hour/loadprojects2 (controller: hour and action: loadprojects2) and at the same time you only have action: loadprojects1(). Also please try this:


$dropdown='<select id="someid">';

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

{

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


}

$dropDown .= '</select>';