event on Active $form->field textInput


Is there a way to add a javascript, based on an event (onclick, onchange…)

to a $form->field ?

And it is a normal textInput, no Dropdown!

<?= $form->field($detail, 'vacancy_lat')->textInput(['maxlength' => true]) ?>

I’m also looking for the same with a HTML::helper field

echo yii\helpers\Html::textInput('lon', $lon, ['id' => 'lon'])

Thank you.

You can try this…

<?= $form->field($detail, 'vacancy_lat')->textInput(['maxlength' => true, 'onclick' => 'js:alert("Clicked me");' ]) ?>

you can use function() in ‘onclick’ attribute like

'onclick' => 'js:function(this.value) { alert(this.value); }'

1 Like

Thank you, it works!

And for a HTML::helper field:

echo yii\helpers\Html::textInput('lon', $lon, ['id' => 'lon','onclick' => 'alert("Clicked me")']);