1$("#select1").change(function() {
2 if ($(this).data('options') === undefined) {
3 /*Taking an array of all options-2 and kind of embedding it on the select1*/
4 $(this).data('options', $('#select2 option').clone());
5 }
6 var id = $(this).val();
7 var options = $(this).data('options').filter('[value=' + id + ']');
8 $('#select2').html(options);
9});