Yii2 - dropDownList 填充 textInput
Yii2 - dropDownList to populate textInput
我有这个观点:
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'name')->dropDownList(['E' => 'Data Entry', 'S' => 'Mark Entry'], ['prompt' => 'Select Option']) ?>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'detail')->textInput(['maxlength' => 20, 'placeholder' => $model->getAttributeLabel('detail')]) ?>
</div>
我想要实现的是,当我点击 dropDownList
时,如果值为 Data Entry 那么 textInput 将是 Data条目。那么如果值为 Mark Entry,那么 textInput 将是 Mark Entry.
如何实现?
您可以为每个输入设置 id
属性以通过 jQuery:
获取它们的值
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'name')->dropDownList(['E' => 'Data Entry', 'S' => 'Mark Entry'], ['id' => 'firstInput', prompt'=>'Select Option']) ?>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'detail')->textInput(['id' => 'secondInput', maxlength' => 20, 'placeholder' => $model->getAttributeLabel('detail')]) ?>
</div>
你的jQuery代码:
$('#firstInput').change(function() {
var firstInputValue = $(this).val();
$('#secondInput').val(firstInputValue);
});
我有这个观点:
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'name')->dropDownList(['E' => 'Data Entry', 'S' => 'Mark Entry'], ['prompt' => 'Select Option']) ?>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'detail')->textInput(['maxlength' => 20, 'placeholder' => $model->getAttributeLabel('detail')]) ?>
</div>
我想要实现的是,当我点击 dropDownList
时,如果值为 Data Entry 那么 textInput 将是 Data条目。那么如果值为 Mark Entry,那么 textInput 将是 Mark Entry.
如何实现?
您可以为每个输入设置 id
属性以通过 jQuery:
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'name')->dropDownList(['E' => 'Data Entry', 'S' => 'Mark Entry'], ['id' => 'firstInput', prompt'=>'Select Option']) ?>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12">
<?= $form->field($model, 'detail')->textInput(['id' => 'secondInput', maxlength' => 20, 'placeholder' => $model->getAttributeLabel('detail')]) ?>
</div>
你的jQuery代码:
$('#firstInput').change(function() {
var firstInputValue = $(this).val();
$('#secondInput').val(firstInputValue);
});