jQuery – 2 dropdown's-Collection of common programming errors
Try this way:-
Demo
var id = this.value;//Get the value of the option.
var options = $(this).data('options'); //get all the saved options.
if (id) { //if there is value then filter it out
options = $(this).data('options').filter('[value=' + id + ']');
}
$('#select2').html(options).prop('selectedIndex', 0); //save option and set selectedindex to first element.
Originally posted 2013-11-09 18:42:01.