murugan
(Rettaikulamram)
1
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’>
<th>Session</th>
<th>Period</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
<?php
for($i=0,$ex=$form->timetable;$i<=$totaldays;$i++)
{$ex=$form->timetable;
?>
<tr>
<td><?php //echo CHtml::dropDownList('sessions['.$i.']',$selectsession[$i],$sessiondrop,array('name'=>'sessions','submit'=>array(''),'prompt'=>'---Select Session---'));
echo CHtml::dropDownList('sessions['.$i.']',$selectsession[$i],$sessiondrop,array('prompt'=>'---Select Session---'));?>
<td><?php echo CHtml::textField('period['.$i.']',$periodvalue[$i],array('readonly'=>'readonly','size'=>'12')); ?></td>
<td><?php echo CHtml::textField('starttime['.$i.']',$starttimevalue[$i],array('readonly'=>'readonly','size'=>'12')); ?></td>
<td><?php echo CHtml::textField('endtime['.$i.']',$endtimevalue[$i],array('readonly'=>'readonly','size'=>'12')); ?></td>
</tr>
<?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 = session.id;
var expSessionId = sessionId.split("_");
var id = expSessionId[2];
$.ajax({
type:'POST',
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];
}
});
}
</script>
$incCnt = 0;
for ($i = 1; $i <= 3; $i++) {
?><tr>
<td><?php
$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>
<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>
</tr><?php
$incCnt += 3;
}
Let me know if you face any further query/concern regarding this.
Thanks
Saurabh