Two Dropdown Depend On One Dropdown


I’ve searching through the internet for about 4 days but I still cannot figure out, my problem is any idea how to make two dropdownlist depend on one dropdownlist? I manage to do one to one. Hopefully, someone can answer my question. I’m new in ajax and yii. Any link for reference is appreciate


 <div class="row">

        <!-- LOCATION -->

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

        <?php echo $form->dropDownList($model,'locationid',

            CHtml::listData(location::model()->findAllbysql('select id,CONCAT(description, " (", code ,")") as description from tbllocation'), 'id', 'description'),




                    'url'=> $ajaxUrl,







                ),'prompt'=>'<please select>'

                /* 'ajax'=>array(






        ); ?>

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


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

        <?php echo $form->dropDownList($model,'blockid',array()); ?>

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

 <div class="row">

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

       <?php echo $form->dropDownList($model,'divisionid',array()); ?>

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



public function actionSelectdos()


        $id_uno = $_POST['fieldmaster']['locationid'];

        $lista = division::model()->findAll('locationid = :id_uno', array(':id_uno'=>$id_uno));

        $lista = CHtml::listData($lista, 'id', 'description');

        echo "<option value = '0'><please select></option>";

        foreach($lista as $valor => $description){

            echo CHtml::tag('option', array('value'=>$valor),CHtml::encode($description), true);




First try to change your Ajax call update to a function.


I don’t have available code, but below is one example, which depends one Ajax call return data to fill two fields.





Next, you need change your actionSelectdos function in the controller, so it can return two arrays in JSON encode after Ajax call. Below is one example tell you how to do that: Basically, it’s return an array and use Jason encoded. The only difference is you need create two arrays and merge into one return to ajax callback.


	 * Ajax call: Find a field engineer.


	public function actionFindEngineer()






			$engineers = User::model()->findAll(array(

					'condition'=>'user_firstname LIKE :name OR user_lastname LIKE :name OR user_email LIKE :name',

					//'order'=>'user_firstname, user_lastname',





				foreach($engineers as $engineer)


					//Below is used for CJuiAutoComplete

					$return[]=$engineer->fullname.' ('.$engineer->user_email.')';



			//add IM engineer name from tool_request_form

			$additional_engineers = Contact::model()->findAll(array(

					'condition'=>'contact_firstname LIKE :name OR contact_lastname LIKE :name OR contact_email LIKE :name',







				foreach($additional_engineers as $engineer)


					$info=$engineer->fullname.' ('.$engineer->contact_email.')';

					if(!in_array($info, $ret))








		echo CJSON::encode($return);



Then depends on these return data, create your drop down list in Ajax update function.

I don’t know if it’s good enough to help you.

Thank you so much bro… I really appreciate… I’ve found out the solution… :)

You can share your solution to help others.

Please can you share the solution with me. I have similar problem.