admin管理员组

文章数量:1332395

This is my code :

<?= $form->field($model, 'int_roomCatId')
          ->dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('class' =>'form-control','prompt'=>'Select Room Category'))
          ->label('Room Category');  ?>

I want to add onchange = "getData()" event. where to add this?

This is my code :

<?= $form->field($model, 'int_roomCatId')
          ->dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('class' =>'form-control','prompt'=>'Select Room Category'))
          ->label('Room Category');  ?>

I want to add onchange = "getData()" event. where to add this?

Share Improve this question asked Nov 25, 2014 at 7:16 KartzKartz 5333 gold badges8 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

In your htmloptions array just do like below:

dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('onchange'=>'getData()','class' =>'form-control','prompt'=>'Select Room Category'))

Each key and value in htmloptions array will be converted to html attributes, for example:

'key'=>'value'

Will be shown as :

<tag key="value" /> 

You can call using below:

<?= $form->field($model, 'product_name')->dropDownList(ArrayHelper::map(Products::find()->all(), 'id', 'name'), 
             ['prompt'=>'-Choose a Product-',
              'onchange'=>'
                $.get( "index.php?r=suborders/listprice&id="+$(this).val(), function( data ) {
                  $( "#suborders-product_price" ).val( data );
                });
            ']);
    ?>

Hope this help you.

Here's how I did it:

    echo $form->field($flightSearchForm, "lastDepartTimeChange", 
        ['options' => ['class' => 'col-xs-12', 
                       'onchange' => "changeHidden(\"departFlightTimeMin\")"]
         ])->widget(\yii\jui\SliderInput::classname());

As you can see, I just put it in the HTML options array which is the third input to the $form->field function. Hope this helps!

本文标签: javascriptYii2How to add onchange event in activeformStack Overflow