Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select2 drop down change event not working

I am using Select2 drop down and I need to do some functionalities based on the the drop down selection.

I have tried the following code, but it didn't worked for me.

$eventSelect.on("select2:select", function (e) { log("select2:select", e); });

$eventSelect.on("change", function (e) { log("change"); });

Can anyone tell me how can I make this work?

like image 382
arunraj6 Avatar asked Jun 24 '17 10:06

arunraj6


3 Answers

I am using select2 version 3.3.2 and the following code is working for me

$("#id").on("change", function () { debugger; });
like image 106
arunraj6 Avatar answered Nov 01 '22 07:11

arunraj6


You can try declaring the event after you know the web page has fully loaded, in my case, this was the problem:

$(document).ready(function(){
    $('#yourselect').on("select2:select", function(e) { 
        console.log($(this).val());
    });
});
like image 6
Jeison Flórez Avatar answered Nov 01 '22 05:11

Jeison Flórez


$(document).on('change', '.js-example-basic-single', function(e) {
console.log($(this).val());})
like image 2
Adrian Avatar answered Nov 01 '22 07:11

Adrian