Question

In Yii 1 i could set onchange event for dropDownList by this method:

CHtml::dropDownList('id', $select, $list, array('onchange'=>'this.form.submit()'))

And it was pretty good. But in Yii 2 it doesn't work, how do i solve this issue?

Was it helpful?

Solution

this code submits on change properly:

<?php use yii\helpers\Html; ?>
  <?= Html::beginForm() ?>
  <?= Html::dropDownList(
    'test', //name
    'b',  //select
    ['a'=>'A', 'b'=>'B'], //items
    ['onchange'=>'this.form.submit()'] //options
  )?>
  <?= Html::endForm() ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top