How to update multiple field with ajax

Hi

I have one dropdown list on my form

If I want to update an other field in the form (a dependant dropdown siteId for exemple), I use this code :




   echo CHtml::dropDownList(	'groupeId', //cbxName

    				'', //selected value

        			CHtml::listData($dataGroupe,'id','nom'), 

        			array( //data

                                   'ajax' => array( 'type'=>'POST', //request type

                                                    'url'=>CController::createUrl('manage/cbxGroupeChange'), 

                                                    'update'=>'#siteId', 

                                             ),		

				   'prompt'=>'Groupes',

				   ),

				array( )

                             ); 



But If I want to update both the siteId dropdown and another field, how to proceed ???

thanks

Hi! Use ‘success’ parameter instead ‘update’




 echo CHtml::dropDownList(    'groupeId', //cbxName

                                '', //selected value

                                CHtml::listData($dataGroupe,'id','nom'), 

                                array( //data

                                   'ajax' => array( 'type'=>'POST', //request type

                                                    'url'=>CController::createUrl('manage/cbxGroupeChange'), 

                                                    'success'=>'updateFields',        

                                                    'dataType' => 'json',

                                             ),         

                                  

                                   'prompt'=>'Groupes',

                                   ),

                                array( )

                             ); <script type="javascript">

function updateFields(data){

   $('#siteId').html(data.value1);

   $('#otherfield').html(data.value2);

</script>



To use ‘data’ parameter with 2 or more fields, encode your result from ‘cbxGroupeChange’ with JSON.

It works

Thanks a lot

I want to update multiple drop downs(Dropdownlist) on selecting the items from the listbox. Please help me.

I want to call two ajax request on one action. Mean I have one drop downlistbox and I want to call two urls (actions as ajax requests ) on selecting the item in drop down, this request results should update the Two drop downs.

I had a similar problem: depending on a checkbox value I wanted to populate two drop down lists with different data. I called just one action, where I populated an array with two variables for both of the drop down lists. I used variables with strings of concatenated <option> tag instead of arrays.