gpt4 book ai didi

php - 如何在 Yii 中不刷新页面的情况下更新下拉列表更改时的文本字段?

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:06 25 4
gpt4 key购买 nike

我有一个 Yii 下拉列表和文本字段,当我选择下拉列表项时,这个名称应该显示在文本字段中。我使用 ajax 尝试了这个概念,但它仅在页面刷新后更新。我已将我的代码粘贴到此处,请查看并建议我如何设置每次立即选择下拉列表项后的文本字段。

   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>

这是 Controller Action :

    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,它只是一个简单的javascript/jQuery

只需这样做(将 editor1 替换为您的 ckeditor 实例名称):

<script>
$("#send_bcfield").change(function(){
var selected = $("#send_bcfield option:selected").val();
CKEDITOR.instances.editor1.setData(selected);
});
</script>

或者将您的代码更改为:

<?php
echo CHtml::activedropDownList(ScriptQuestion::model(), 'crm_base_contact_form_field_id', $select_field, array(
'id' => 'send_bcfield',
'class' => 'col_165',
'onchange' => '$("#send_bcfield").change(function(){
var selected = $("#send_bcfield option:selected").val();
CKEDITOR.instances.editor1.setData(selected);
});',
)
);
?>

更新:根据您在我的回答下方的评论,我将代码更改为更改 ckeditor 值

关于php - 如何在 Yii 中不刷新页面的情况下更新下拉列表更改时的文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com