我有一個Yii下拉列表和文本框,當我選擇下拉列表項時,這個名字應該顯示在文本框中。我嘗試使用ajax這個概念,但它更新後頁面刷新only.I已粘貼我的代碼在這裏,請透視,並建議我如何設置 textfield後立即選擇下拉列表項目。如何在沒有刷新頁面的情況下更新dropdownlist的textfield onchange?
The following code resides protected/views/form
<td>
<?php echo $form->labelEx(ScriptQuestion::model(),'Field'); ?></td><td>
<?php echo CHtml::activedropDownList(ScriptQuestion::model(),'crm_base_contact_form_field_id',$select_field,
array(
'id' => 'send_bcfield',
'class' => 'col_165',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('DisplayMessage'),
'update' => '#question_editor',
'data' => array('bcfield' => 'js:this.value'),
'success'=> 'function(data) {$("#question_editor").empty();
$("#question_editor").val(data);
} ',
))
); ?>
</td>
<td>
<?php echo $form->textArea($model, 'message', array('id'=>'question_editor','maxlength'=>508,)); ?>
</td>
這是控制器動作:
public function actionDisplayMessage(){
$q = $_POST['bcfield'];
$model=ScriptQuestion::model()->findAll();
$sql = "SELECT name FROM crm_field WHERE crm_field_id=". $q ;
$command = Yii::app()->db->createCommand($sql);
$result= $command->queryScalar();
echo "%".$result."%";
$this->performAjaxValidation($model);
}
你必須發送Ajax請求'onchange' –
你的意思是不是成功的onchange? – Bala
嘗試在'成功'部分提醒'數據',並告訴我它是什麼 –