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?
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