I am using Select2 Widget In yii Framework and want to call function on change event but its not working
Yii::import('ext.select2.Select2');
echo Select2::activeMultiSelect($categoryModel, "cat_name", CHtml::listData(
Category::model()->findAllByAttributes(array('cat_type' => 'Recipe')), 'id', 'cat_name'), array(
'placeholder' => 'Select Category',
'select2Options' => array(
'maximumSelectionSize' => 5,
'events' => array('change' => 'js:function(){ alert("asdfasdfasdfasdfasdf"); }')
),
));
i am going to alert message on change but this not works and not show any error message or something on console thanks in advance
You can try adding an id
to your select
, then bind your function to its click event with jQuery like this in the footer of your page:
$("#selectID").click(function () {
alert("Selected value is: " + $("#selectID").select2("val"));
});