dropDownList change setState variable

Hi!

I trying to use a dropodownlist to changue a user session variable "carpeta".


<?php 		

	echo CHtml::dropDownList('cliente','',CHtml::listData(Clientes::model()->findAll(),'id_cliente','nombre'),

                   array(

                          'empty'=>'- Selecciona un cliente -',

                          'onchange'=>Yii::app()->user->setState('carpeta', OPTION-SELECTED),                     	                              

                     ));

?>

Is this possible?? thanks!

Is not possible, here you should write a js function.

You can use onChange for fire an ajax request, wich calls an action wich set your variable.

Ok, I solved with an action call:


<?php 		

		echo CHtml::dropDownList('cliente','',CHtml::listData(Clientes::model()->findAll(),'id_cliente','nombre'),

                            array(

                            	'empty'=>'- Selecciona un cliente -',                            	

                            	'onchange'=>'js:$("#cargar-archivo").slideDown("slow")',

                            	'ajax'=>array(                            

                            		'type' => 'POST',

	                                'url' => Yii::app()->createUrl('admin/archivos/cambiarcarpeta/'),

	                                'data'=>"js:{clientId: $(this).val()}",	                              

	                            	)                     	                              

                            ));

		 ?>

and,


public function actionCambiarcarpeta()

	{

		$id_cliente=$_POST['clientId'];	

		Yii::app()->user->setState('carpeta',$id_cliente);	

		Yii::app()->end();

	}

thanks zaccaria!

You are welcome, I am glad that it helped.

Hi,

i have this scenario and i don’t know how to adapt this

vehicle type (car / motorcycle)

if i choose car, next dropdown should populate from "car make" table and after selection "car model"

the same for motorcycle

Could you please help me ?