how to use ajax for update Three textfields on changing a dropdownlist

Hi everyone

i have a table which contains each row of one dropdownlist and three textfields

what is my problem means

when i change dropdownlist it must gives(updates) three textfields

i want to use ajax then how to put code for it in view and controller

<table cellpadding="0" width="auto" cellspacing="3" border="1">

<tr height=‘24px’>



&lt;th&gt;Start Time&lt;/th&gt;

&lt;th&gt;End Time&lt;/th&gt;







 &lt;td&gt;&lt;?php //echo CHtml::dropDownList('sessions['.&#036;i.']',&#036;selectsession[&#036;i],&#036;sessiondrop,array('name'=&gt;'sessions','submit'=&gt;array(''),'prompt'=&gt;'---Select Session---'));

 echo CHtml::dropDownList('sessions['.&#036;i.']',&#036;selectsession[&#036;i],&#036;sessiondrop,array('prompt'=&gt;'---Select Session---'));?&gt;

 &lt;td&gt;&lt;?php echo CHtml::textField('period['.&#036;i.']',&#036;periodvalue[&#036;i],array('readonly'=&gt;'readonly','size'=&gt;'12')); ?&gt;&lt;/td&gt;

 &lt;td&gt;&lt;?php echo CHtml::textField('starttime['.&#036;i.']',&#036;starttimevalue[&#036;i],array('readonly'=&gt;'readonly','size'=&gt;'12')); ?&gt;&lt;/td&gt;

 &lt;td&gt;&lt;?php echo CHtml::textField('endtime['.&#036;i.']',&#036;endtimevalue[&#036;i],array('readonly'=&gt;'readonly','size'=&gt;'12')); ?&gt;&lt;/td&gt;


<?php }?></table>

please give idea

You need to call an ajax function on onchange event of dropdownlist in a view, and assign responded values to corresponding textfields as below:

<script type="text/javascript" language="Javascript">

        function changeSession(session) {

                var sessionVal = session.value;

                var sessionId =;

                var expSessionId = sessionId.split("_");

                var id = expSessionId[2];



                        url: "<?php print( $baseUrl . '/commande/getSessionValues');?>",

                        data: {id: sessionVal},

                        success: function(response){                                                

                                var expResponse = response.split(",");

                                document.getElementById("period_" + id).value = expResponse[0];

                                document.getElementById("starttime_" + id).value = expResponse[1];

                                document.getElementById("endtime_" + id).value = expResponse[2];





$incCnt = 0;

for ($i = 1; $i <= 3; $i++) {                                



                        $sessionData[$i] = DropdownDemo::model()->findAll(array('limit' => 3, 'offset' => $incCnt));

                        $arrSessionValues[$i] = CHtml::listData($sessionData[$i], 'id', 'title');

                        echo $form->dropDownList($model, 'session_' . $i, $arrSessionValues[$i], array(

                                'onchange' => 'js: return changeSession(this);'



                <td><?php echo $form->textField($model, 'period_' . $i, array('size' => 60, 'maxlength' => 255)); ?></td>

                <td><?php echo $form->textField($model, 'starttime_' . $i, array('size' => 60, 'maxlength' => 255)); ?></td>

                <td><?php echo $form->textField($model, 'endtime_' . $i, array('size' => 60, 'maxlength' => 255)); ?></td>        


        $incCnt += 3;


Let me know if you face any further query/concern regarding this.