D
D
Denis Rybin2016-06-30 18:47:47
JavaScript
Denis Rybin, 2016-06-30 18:47:47

How to pass the value of one field in the form to a link?

There is a form, you need to insert the entered data from one field into a link, which can then be sent to the server using pjax, that's what I did:

$js = <<<JS
$("#slug-block").hide();
$("#title-input").focusout(function() {
var txt1 = $("#title-input").val();
if(txt1 != ""){
$("#slug-block").show();
}else{
$("#slug-block").hide();
}
});
JS;
$this->registerJs($js);

...

<?= $form->field($model, 'title')->textInput(['id'=>'title-input', 'maxlength' => 64]) ?>
<div id="slug-block">
<?= $form->field($model, 'slug')->textInput(['id'=>'slug-input', 'maxlength' => 64]) ?>

<? Pjax::begin(['enablePushState' => false]); ?>
<?= Html::a('Показать варианты', ['page/slug', 'slug'=>сюда_нужно_вставить_значение_из_title-input); ?>
<? Pjax::end(); ?>
</div><!--/slug-block-->

...

Please tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Rybin, 2016-06-30
@RybinDen

I already think it will be easier to send a post request, just add the value attribute to the link and insert the value from the first field into it.
---
did this
$(link id).attr("href", "required link");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question