0
我试图将javascript中的值放入Yii2中的表单动作中 是否有可能? 更具体地说,我需要对在dropdownList中选择的每个选项进行URL更改。将javascript值传递给Yii2中的表单动作URL
形式的意见/ site.php
$form = ActiveForm::begin([
'id' => 'form',
'method' => 'POST',
'action' => Url::to(['programas/'.Tours::findOne(['pk' => ])->programa]),
]);
<?= $form->field(new \app\models\Tours(), 'nombre')->dropDownList([],
[
'prompt' => 'Programa',
'id' => 'child1_child2',
'onchange' => 'updateValue(this.value)',
]
)->label(false); ?>
JS文件
function updateValue(val){
x = document.getElementById("test").value;
// document.getElementById("form").action = "programas/";
}
所以,我来救从JS所选择的选项的值,但我需要把它放在这里 'pk' 文件>'值'
其中值是#child1_child2选择的选项值。
'action' => Url::to(['programas/'.Tours::findOne(['pk' => ])->programa])
感谢您的帮助。
嘿,感谢这个有很大的帮助:)! – Rugleh