I have two selects:
I have found the solution as followiing... working for me perfectly :)
$(document).ready(function(){
$("#selectbox1").change(function() {
var id = $(this).val();
$("#selectbox2").val(id);
}); });
Store all #select2
's options in a variable, filter them according to the value of the chosen option in #select1
, and set them using .html()
in #select2
:
var $select1 = $( '#select1' ),
$select2 = $( '#select2' ),
$options = $select2.find( 'option' );
$select1.on('change', function() {
$select2.html($options.filter('[value="' + this.value + '"]'));
}).trigger('change');