Problems with dependent dropdown

Hey, I am trying to create a dependent dropdown for my practice site. I found an artile on the Cookbook that did help me understand, but I am still having problems (

       Here is my code...

      For my form I have:

<?php echo CHtml::dropDownList($boycott,'cap', array(1=>'Cap', 2=>'No'),

array( 'prompt'=>'Upper or Lower',

'ajax' => array(

'type'=>'POST', //request type

'url'=>Yii::app()->baseUrl.'Boycott/letter', //url to call

'update'=>'#letter', //selector to update

//'data'=>'js:javascript statement' 

//leave out the data key to pass all form values through




<div class="simple">

<?php echo CHtml::DropDownList($boycott, 'letter', array()); ?>


For my controller:

public function actionDynamiccall()



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



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


			echo CHtml::tag('option',




As for my database, I have three columns: id (int), letter (char), and isCap (boolean).

When I compile and run the code, it works but the other dropdown is blank. I been working with the code, what am I doing wrong?

use the syntax of dropdownlist as

CHtml::dropDownList(‘boycott’,’’, array(1=>‘Cap’, 2=>‘No’)…etc, and similarly for

CHtml::DropDownList(‘leter’, ‘’, array());

i have used like this and got the output u can also try this

Thx for your input, but what did you do with the controller? Did you rename it something different, what did you do?

i did the same that u did…did u get the answer say me exactly what u need so that i can provide you that i knew

Same thing. The error I am getting is a run time error. When I run it, it seems that everything is working except for one thing, The second dropdown isn’t filled. Are you getting a filled dropdown?


in the code you’ve posted above you’re having an action called ‘Dynamiccall()’ in your controller but the action you are calling in your ajax request is ‘letter’ of the controller ‘Boycott’!?

Maybe the problem is just something simple like:

'url'=>Yii::app()->baseUrl.'Boycott/dynamiccall', //url to call



yes what he says may be ur problem try this…change the url to the action that u have code for the second drop down

How about to use the same thing to the CActiveForm:dropDownList?

it doesn’t work for me

the tutorial is made for CHtml and i apply to the CActiveForm:dropDownList, but nothing happen on change… :unsure:

add htmlOPtions "name"

	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'areaIDLink',array(''=&gt;Area::items()),


				'ajax' =&gt; array(

					'type'=&gt;'POST', //request type








	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'equipmentIDLink',array(''=&gt;Equipment::itemx(&#036;model-&gt;areaIDLink)),



public function actionEquip()



              array(':areaIDLink'=&gt;(int) &#036;_POST['areaIDLink']));


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


                echo CHtml::tag('option',



          return self::&#036;data;