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 (http://www.yiiframework.com/doc/cookbook/24/).

       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>

<div class="simple">

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

</div>

For my controller:


public function actionDynamiccall()

	{

		$data=Alphabet::model()->findAll('parent_id=:parent_id', 

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

 

		$data=CHtml::listData($data,'id','letter');

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

		{

			echo CHtml::tag('option',

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

		}

	}

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?

Hi,

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

?

Greets

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()),


			array(


				'ajax' =&gt; array(


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


					'url'=&gt;CController::createUrl('component/equip'),


					'update'=&gt;'#equipmentIDLink',


					),[b]'name'=&gt;'areaIDLink'[/b],'width'=&gt;30,


				)


			


	); 


	?&gt;





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


                          array([b]'name'=&gt;'equipmentIDLink'[/b]));?

CONTROLER

public function actionEquip()


{


              &#036;data=Equipment::model()-&gt;findAll('areaIDLink=:areaIDLink', 


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





              &#036;data=CHtml::listData(&#036;data,'equipmentID','hacCode');


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


                {


                echo CHtml::tag('option',


                array('value'=&gt;&#036;value),CHtml::encode(&#036;hacCode),true);


                }


          return self::&#036;data;


}