Answers for "select2 on change"

2

select2.org events

$('#mySelect2').on('select2:select', function (e) {
    var data = e.params.data;
    console.log(data);
});
Posted by: Guest on July-20-2020
0

select2 on change

<script>
  	$('#exampleSelect2').select2().on('change', function(){
		// ...
	});
</script>
Posted by: Guest on October-23-2021
0

select2 replace options

var options = [];
$.each(dataReturn, function (i, obj) {
    //console.log(i);
    //console.log(obj);
    options.push({
        text: obj.NickName,
        id: obj.NickName
    });
})
$("#BeneType").empty().select2({
    data: options
});
Posted by: Guest on December-28-2020
0

select2 replace options

var initQuantitiesDropdown = function () {
    var options = [];
    var selectedFruit = $("#fruits").val();
    $.each(pageData.products[selectedFruit].quantities, function (key, value) {
        options.push({
            text: value,
            id: key
        });
    })
    $("#quantities").empty().select2({
        data: options
    });
};

$("#fruits").select2().change(initQuantitiesDropdown);
initQuantitiesDropdown();
Posted by: Guest on December-28-2020
0

select2 select value in not changing

any .val() updates need to be followed by
$('#unit').val('21'); // Select the option with a value of '21'
    $('#unit').trigger('change'); // Notify any JS components that the value changed
Posted by: Guest on July-24-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language