使用Javascript在CAtiveForm中预设值
之前,我创建了一个带有dropdownlist和带有CActiveForm的文本字段的页面使用Javascript在CAtiveForm中预设值,javascript,php,yii,Javascript,Php,Yii,之前,我创建了一个带有dropdownlist和带有CActiveForm的文本字段的页面 <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'frm-add-payment-modes', 'enableAjaxValidation' => false, 'htmlOptions'=>array( 'class'=>'
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'frm-add-payment-modes',
'enableAjaxValidation' => false,
'htmlOptions'=>array(
'class'=>'form-horizontal',
)
));
?>
<div class="row">
<div class="col-md-6">
<label class="control-label mbs mts" for=""><?php echo Yii::t ('AdminModule.yii', 'adm.sttng.paymentStting.status'); ?> *</label>
<?php echo $form->dropDownList ($modelEconfigPaypal, 'active', array('0' => 'Inactive', '1' => 'Active'), array ('class' => 'form-control')); ?>
</div>
</div>
该方法没有问题,因为所有文本字段都可以预设该值。但是,dropdownlist不能。我可以知道如何预设CActiveform dropdownlist的值吗?如果它不适用于下拉列表,请与我们共享此下拉列表的代码。@rob006抱歉,只需在第一个图形上编辑即可。您的代码应能正常工作,确保在不同的位置(如具有此ID的更多元素)没有错误,
结果[0]['active']
具有正确的值。
__octAppEditObj.makeAjaxRequest (__basePath + '/admin/settings/getPaymentDetails', data, function (res) {
var result = JSON.parse(res);
console.log(result[0]);
document.getElementById("EconfigPaypal_name").value = result[0]['name'];
document.getElementById("EconfigPaypal_payment_gateway").value = result[0]['payment_gateway'];
document.getElementById("EconfigPaypal_payment_gateway_id").value = result[0]['payment_gateway_id'];
document.getElementById("EconfigPaypal_apiusername").value = result[0]['apiusername'];
document.getElementById("EconfigPaypal_apipassword").value = result[0]['apipassword'];
document.getElementById("EconfigPaypal_active").value = result[0]['active'];
document.getElementById("EconfigPaypal_apilive").value = result[0]['apilive'];
document.getElementById("EconfigPaypal_apisignature").value = result[0]['apisignature'];
document.getElementById("EconfigPaypal_string1").value = result[0]['string1'];
document.getElementById("EconfigPaypal_string2").value = result[0]['string2'];
document.getElementById("EconfigPaypal_string3").value = result[0]['string3'];
});