以yii2格式从另一个字段中获取数据
I'm making a form with yii2, now I have two field:
<?php echo $form->field($model, 'Protocol')->textInput(['maxlength' => true])->dropDownList(
array("rtsp://"=>"rtsp","rsmt://"=>"rsmt","http://"=>"http"), // Flat array ('id'=>'label')
['prompt'=>'Select'] // options
); ?>
<?php echo $form->field($model, 'url')->textInput(['maxlength' => true]); ?>
How can I take the selection from Protocol's drop down list and automatically add it to the below URL field? Like this: I type the
http://
in the field manually, is there anyway I can make it automatic?
我正在用yii2创建一个表单,现在我有两个字段: p>
我怎样才能参加 从协议的下拉列表中选择并自动将其添加到以下URL字段? 像这样: &lt;?php echo $ form-&gt; field($ model,'Protocol') - &gt; textInput(['maxlength'=&gt; true]) - &gt; dropDownList(
array(“rtsp”) ://“=&gt;”rtsp“,”rsmt://“=&gt;”rsmt“,”http://“=&gt;”http“),//平面数组('id'=&gt;' label')
['prompt'=&gt;'选择'] // options
); ?&gt;
&lt;?php echo $ form-&gt; field($ model,'url') - &gt; textInput(['maxlength'=&gt; true]); ?&gt;
code> pre>
我手动在字段中输入
http:// code>,无论如何我可以自动进行吗? p>
Add onchange
event in your 'protocol'
dropdownList. show below code
<?= $form->field($model, 'Protocol')->dropdownList(["rtsp://"=>"rtsp","rsmt://"=>"rsmt","http://"=>"http"], [
'onchange'=>'$( "#'.Html::getInputId($model, 'url').'").val($(this).val());'
]) ?>
<?= $form->field($model, 'url')->textInput(['maxlength' => true]);
?>