Hi, I need a help here. Currently, I am having 1 dropdownlist, 1 dependent dropdownlist and 1 textfield for my submitted form. Both of the dropdownlist are working perfectly but not for the textfield.
I wish to have a value return on the textfield after I have selected the dependent dropdownlist. Any idea how to solve this problem? Any help is appreciated. Please help me~ Thank you.
Here’s my code:
view file
//dropdownlist
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'code'); ?>
<div style="margin-left:110px; margin-top:-30px">
<?php echo $form->dropDownList($model,'code', CHtml::listData(Course::model()->findAll(), 'code', 'code'), array(
'empty'=>'Please Select Course Code',
'ajax'=> array(
'type'=>'Post',
'url'=>CController::createUrl('Exam/getcode2'),
'update'=>'#'.CHtml::activeId($model,'code2'),
'data'=>array('code'=>'js:this.value'),
))); ?>
</div></div></br>
//dependent dropdownlist
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'code2'); ?>
<div style="margin-left:110px; margin-top:-30px">
<?php echo $form->dropDownList($model,'code2', array(),array(
'empty'=>'Please Select Course Code',
'ajax'=> array(
'type'=>'Post',
'url'=>CController::createUrl('Exam/getname'),
'update'=>'#'.CHtml::activeId($model,'name'),
'data'=>array('code2'=>'js:this.value'),
))); ?>
</div></div></br>
//textfield
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'name'); ?>
<div style="margin-left:110px; margin-top:-30px">
<?php echo $form->textfield($model,'name', array(''));?>
</div></div></br>
controller file
public function actionGetcode2()
{
$data=Course::model()->findAll('code=:code',
array(':code'=> $_POST['code']));
$data=CHtml::listData($data,'code2','code2');
foreach($data as $value=>$code2)
{
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($code2),true);
}
}
public function actionGetname()
{
//how to populate the value for textfield after select the dependent dropdownlist
}