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 badges3 Answers
Reset to default 1In 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
版权声明:本文标题:javascript - Yii2 - How to add onchange event in activeform - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742283340a2446499.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论