Dropdownlist Select From Parent

i have 3 levels of dropdownlist

i have to select first the behavior type [negative, positive)

based on the type, i have to select the behavior group and finally the behavior

i am beginner in yii and ajax, i got an example from the internet and i tried to apply it to yii

the example didn’t work in yii, but it’s workable in pure php

can anyone tell me where is the error.

thanks in advance

4273

_formcreate.php

i tried also based on this website

_form is




<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'assignment-form',

	'enableAjaxValidation'=>false,

	'enableClientValidation'=>true,

)); 


?>


<?php echo $form->dropDownList($model,'BehavType', array(Yii::app()->params['bType']),array('empty'=>'Select Type'),

array(

'ajax' => array(

'type'=>'GET', //request type

'url'=>$this->createUrl('Assignment/getBehaviorGroup'), //url to call.

//Style: CController::createUrl('currentController/methodToCall')

'data'=>array('BehavType'=>'js:this.value'),

//'data'=>array('BehavType'=>'js:this.value'), 

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

))); 

 

//empty since it will be filled by the other dropdown

echo $form->dropDownList($model,'behavGroupID', array()); ?>


	



in Assignment controller




		public function actionGetBehaviorGroup()

	{

		$data=Category::model()->GetCatOfType($_POST['BehavType']);//findAll('parent_id=:parent_id', array(':parent_id'=>(int) $_POST['BehavType']));

	

		$data=CHtml::listData($data,'color','color');

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

		{

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

		}

		

		//echo $_POST['BehavType'];

	}




public function accessRules()

	{

		return array(

		

			array('allow',

				'actions'=>array('index','create','admin','view','update','assign', 'getBehaviorGroup'),

				'roles'=>array('admin','BASAdmin','Assistant','Teacher'),

				'users'=>array('@'),

			),

}






there is no result, it seems that the first dropdownlist doesn;t even go to the controller. is there any errors in this code?

Have you checked your ajax response (via Firebug)? Does it show some errors?

yes, there is no error.

i putted an alert at the beginning of the ajaxfunction to see if the ajax code is executed. there is no result. it seems that the ajax code is not visible.

the code is works now fine for me. but i need to use $form->dropdownlist in the second dropdownlist instead of CHtml::dropdownlist in order to save the selected value in the database. and i use $form->dropdownlist, the second list is empty even the result appeared in the firebug but not displayed in the html view.

how to solve this issue?

this is the code

in view




<div class="row">

		<?php

			//  select the Behavior Type

			echo $form->dropDownList($model,'BehavType', array(Yii::app()->params['bType']),

					array(

					'ajax' => array(

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

						'url'=>CController::createUrl('Assignment/getBehaviorGroup'), //url to call.

						'update'=>'#behavGroupID',

					))); 

		?>

	</div>

	<div class="row">

		<?php

			//  select the Behavior Group 

			echo $form->dropDownList($model,'behavGroupID',  array(),

					array(

					'ajax' => array(

						'type'=>'POST', 

						'url'=>CController::createUrl('Assignment/getBehavior'), //url to call.

						'update'=>'#behavID',

					))); 

									

			echo $form->error($model,'behavGroupID');

			echo "&nbsp &nbsp";

			

			//  select the Behavior

			echo $form->dropDownList($model,'behavID',array());

			echo $form->error($model,'behavID');

		?>

	</div>



in the controller




	public function actionGetBehaviorGroup()

	{

		$assignment = Assignment::model()->GetAssignmentInfo($_POST['Assignment']['BehavType']);

		

		$data=CHtml::listData($assignment,'ID','E_BGName');

		

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

		{

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

		}

	}

	

	public function actionGetBehavior()

	{

		$behavior = Behavior::model()->findAll('behavGroupID=\'' . $_POST['Assignment']['behavGroupID'] . '\'');

		$data=CHtml::listData($behavior,'ID','E_Name');

		

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

		{

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

		}

	}