Hey,
I just started using select2 for my dynamic ajax dropdowns. But I just cant read/get the selected option and/or its value. All my options are loaded remotely via ajax, are shown corretly and selecting them works too.
I initialize the select like so:
`$('#city').empty();
$('#city').select2({
dropdownParent: $('#city').parent(),
placeholder: 'Please pick your city..',
ajax: {
url: '<?php echo Config::get('URL'); ?>xxxxxxx/GetAllCities',
dataType: 'json',
data: function (params) {
var query = {
search: params.term,
type: 'public'
}
return query;
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
});`
but if I then want to get the value and/or the selected option, I get the error “undefined”:
$('#city').children("option:selected").val()
I am using the newest select2 release /w jquery 3.4.1
What am I doing wrong?