Reputation: 227
I would like to reset the first list when second is active and reset second list when first list is active(to return to Choose an option...)...I use select2 Jquery plugin. I tried with the code
$('#second').change(function(){
$('#first').prop('selectedIndex',0);
});
$('#first').change(function(){
$('#second').prop('selectedIndex',0);
});
but it does not work. Code is here
Upvotes: 1
Views: 777
Reputation: 123739
You can use select2
overload's val
method to pass-in the first options value (if it has) to reset it.
$('#second').change(function(){
$('#first').select2('val','');
});
$('#first').change(function(){
$('#second').select2('val','');
});
See Doc
val : Gets or sets the selection. If the value parameter is not specified, the id attribute of the currently selected element is returned. If the value parameter is specified it will become the current selection.
Upvotes: 2