Dropdown change event
Read the chosen value and the visible text of the selected option.
jQuery · Dropdown change eventBeginner
$('#country').on('change', function () {
const value = $(this).val(); // 'pk'
const label = $(this).find('option:selected').text(); // 'Pakistan'
$('#out').text(label + ' (' + value + ')');
});
$('#country').val('pk').trigger('change'); // set it from codeselectchangeoptionval