yii2 How to send the textInput value to another textInput

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() ?>



What I want to do is that while typing into Test1’s (textInput), the value of Test1’s (textInput) will automatically appear in Test2’s (textInput).

How do I achieve this.

I’ve resolved it. I added this to the view




$this->registerJs('

    jQuery(document).on("keyup" ,"#'. Html::getInputId($model ,'Test1') .'" ,function(){

        $("#'. Html::getInputId($user ,'Test2') .'").val();

        var first = $("#'. Html::getInputId($model ,'Test1') .'").val();

        var second = first;

        $("#'. Html::getInputId($user ,'Test2') .'").val(second);


    });