Hey guys,
what I wanna do is to have a page with a Dropdownlist. When a user clicks on a menu entry the next step (also a dropdownmenu) shall be visible (later on there shall be a dependance but right now I ONLY want to DISPLAY the other dropdown menu when the user clicked an entry in the first one).
So that’s my code in the view:
echo CHtml::dropDownList('cat0_name','',$list,
array(
'prompt'=>'Kategorie wählen',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('loadcities'),
'replace'=>'#cat1_name',
'data'=>array('id'=>'js:this.value', 'step' => 1),
)));
echo CHtml::dropDownList('cat1_name','', array(), array('style'=>'display:none;','prompt'=>'Select Stuff'));
echo CHtml::dropDownList('cat2_name','', array(), array('style'=>'display:none;','prompt'=>'Select Stuff'));
What I’ve tried to do is to replace a dropdownlist with invisible style with a dropdownlist that has my content.
The controller code:
public function actionLoadcities()
{
/*$data=CnfCategory::model()->findAll('id=:id',
array(':id'=>(int) $_POST['id']));
$data=CHtml::listData($data,'id','cat_name');*/
$models = CnfCategory::model()->findAll();
$data = CHtml::listData($models,
'id', 'plural');
$step = $_POST['step'];
//$step=0;
echo CHtml::dropDownList('cat'.$step.'_name','',$data,
array(
'prompt'=>'Kategorie wählen ',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('loadcities'),
'replace'=>'#cat'.($step+1).'_name',
'data'=>array('id'=>'js:this.value', 'step' => $step+1),
)));
}
What is going wrong here? When I try to do this and inspect the page with firebug no request is called after I click on an entry in the second dropdown menu. If I set the step to 0 (which i commented here) there is at least a post request but nothing happens that’s very weird.
I hope some of you can help me with this!! Even if you know a better method how to do that I would really like to know what’s the problem here.