jquery - Disabling <select> option based on other <select> option -
how disable multiple options in select, in case exact options selected in other selects. found answered question problem similar mine on link: http://jsfiddle.net/dzqeu/
jquery code looks next:
$(this).siblings('select').children('option').each(function() { if ( $(this).val() === value ) { $(this).attr('disabled', true).siblings().removeattr('disabled'); }
the problem works 2 selects. need total 3 selects should disable possibility same values in selects selected.
this code won't work 3 selects: http://jsfiddle.net/dzqeu/968/
tnx in advance
note:
when select1 set 1, select 2 set 2, can't disable values 1&2 in select3. disables value 2 in select 3...
try this:- http://jsfiddle.net/z2yag/
using focus prev value , remove disabled ones. in html have added value -1 default option.
<option value="-1">no match</option> var prev = -1; $("select").change(function () { if ($(this).val() > -1) { $("select").not(this).find("option[value=" + $(this).val() + "]").attr('disabled', 'disabled'); } $("select").not(this).find("option[value=" + previous + "]").removeattr('disabled'); }).focus(function () { previous = $(this).val(); });