Reputation: 95
I am new for Yii2 and I have a question.
In my _form.php (generated automatically by gii) I have two fields (textInput)
<?= $form->field($model, 'Test1')->textInput() ?>
<?= $form->field($model, 'Test2')->textInput() ?>
I want to get Test1's (textInput) value and get Test2's value, and send the total value to another textInput.
<?= $form->field($model, 'Test3')->textInput() ?>
I want to see the total value in the Test3 (textInput).
Can anyone help me please..
Upvotes: 0
Views: 1648
Reputation: 4160
This can be done by adding custom javascript in your view
<?php
$this->registerJs('
jQuery(document).on("change" ,"#'. Html::getInputId($model ,'Test2') .'" ,function(){
$("#'. Html::getInputId($model ,'Test3') .'").val();
var first = $("#'. Html::getInputId($model ,'Test1') .'").val();
var second = $("#'. Html::getInputId($model ,'Test2') .'").val();
var third = first +" " + second;
$("#'. Html::getInputId($model ,'Test3') .'").val(third);
});
');
?>
Upvotes: 1
Reputation: 511
Test3
to your model as property.public function getTest3()
{
return $this->Test1 . " " . $this->Test2;
}
Upvotes: 1