four dependent dropdownlist


I made these 4dependent dropdownlist when I select the first , the second will update and when I select the second the third will update .....

but I want when I select the first all next 3 dropdown updated automatically.

these dropdownd in _form.php


$serv4=CHtml::listData(FullTableController::prov_func(),'prov','prov');  

    echo $form->dropDownList($model,'Province',$serv4, 

array(

'ajax' => array(

    

'type'=>'POST', 

   

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

'url'=>CController::createUrl('FullTable/dynamiccities'), 

'update'=>'#FullTable_Site_Name', 

   

))); 

////////////////////////////////////////////////////////////////////////////////////////////////////////

echo $form->dropDownList($model,'Site_Name',array(),

        array( 

             

            'ajax'=>array(

              

            'type'=>'POST',

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

'url'=>CController::createUrl('FullTable/dynamiccities2'), 

'update'=>'#FullTable_Site_ID', 

             


)));     

////////////////////////////////////////////////////////////////////////////////////////////////////////

cho $form->dropDownList($model,'Site_ID',array(),

        array(

            'ajax'=>array(

            'type'=>'POST',

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

'url'=>CController::createUrl('FullTable/dynamiccities3'), 

'update'=>'#FullTable_Servity', 

   

))); 

  echo $form->labelEx($model,'Servity'); 

echo $form->dropDownList($model,'Servity',array());

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

?>



FullTable Controller.php




 public function actionDynamiccities()

{

    $data=Sites::model()->findAll('prov_n=:prov_n OR " "=Site_Name ORDER BY Site_Name', 

                  array(':prov_n'=> $_POST['prov_n']));

 

    $data=CHtml::listData($data,'Site_Name','Site_Name');

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

    {

        echo CHtml::tag('option',

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

    }

}

public function actionDynamiccities2()

{

    $data=Sites::model()->findAll('Site_Name=:Site_Name OR " "=Site_Name ORDER BY Site_id', 

                  array(':Site_Name'=> $_POST['Site_Name']));

 

    $data=CHtml::listData($data,'Site_id','Site_id');

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

    {

        echo CHtml::tag('option',

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

    }

}

public function actionDynamiccities3()

{

    $data=Sites::model()->findAll('Site_id=:Site_id', 

                  array(':Site_id'=> $_POST['Site_id']));

 

    $data=CHtml::listData($data,'servity','servity');

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

    {

        echo CHtml::tag('option',

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

    }

}



Currently the action for the first dropdown returns values for the second one… and in the code you specify to update that secod dropdown…

If you want the first dropdown to update all the other dropdowns (more than one)… you would need to return all those value for all the other dropdowns together as the result of the first dropdown action, but you need a way to "know" what goes where… JSON array comes to mind…

so you need something like




array(

   'firstdropdownvalues'=>array(...),

   'seconddropdownvalues'=>array(...),

)



And you should not use "update" CHtml::ajax() option as this is used to update only one container (one dropdown)… instead use "success" and a custom function that would take the JSON array and update the other dropdowns…