Yii Framework Forum: How to update multiple field with ajax - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to update multiple field with ajax Rate Topic: -----

#1 User is offline   chtibob69 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 13-February 11

Posted 18 March 2011 - 04:20 PM

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
0

#2 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 30 March 2011 - 07:28 AM

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.
Yes, It Is!
1

#3 User is offline   chtibob69 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 13-February 11

Posted 30 March 2011 - 02:23 PM

It works

Thanks a lot
0

#4 User is offline   Vip 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 21-October 11
  • Location:Gwalior,India

Posted 09 November 2011 - 06:28 AM

I want to update multiple drop downs(Dropdownlist) on selecting the items from the listbox. Please help me.
Vipul Arora
Gwalior
India,
0

#5 User is offline   Vip 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 21-October 11
  • Location:Gwalior,India

Posted 26 November 2011 - 06:50 AM

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.
Vipul Arora
Gwalior
India,
0

#6 User is offline   wuadziu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 28-November 11
  • Location:Dresden/Saxony

Posted 28 November 2011 - 09:01 AM

View PostVip, on 26 November 2011 - 06:50 AM, said:

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users