I have a question similar to the one asked here: jQuery <select> option disabled if selected in other <select>
But, mine varies in that there will be more than two select boxes. In the answer provided, when an option is selected, it is set to disabled in the other select boxes (which I want to happen), but I don't want any other options selected in a different select box to have disabled removed.
Does that make sense?
Example html:
<div>
<select name="homepage_select_first">
<option>No Match</option>
<option value="1">Test</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
</div>
<div>
<select name="homepage_select_second">
<option>No Match</option>
<option value="1">Test</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
</div>
<div>
<select name="homepage_select_third">
<option>No Match</option>
<option value="1">Test</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
</div>
And the jQuery:
$('select[name*="homepage_select"]').change(function() {
var value = $(this).val();
alert(value);
$('select[name*="homepage_select"]').children('option').each(function(){
if ( $(this).val() === value ) {
$(this).attr('disabled', true)//.siblings().removeAttr('disabled');
}
});
});
Commenting out .siblings().removeAttr('disabled')
simply never removes the disabled attribute...but, I want to remove it ONLY if it isn't selected in any one of the select boxes.
Basically, I only want an option to be selected in one of the selects at a time. I would think that if I could only .removeAttr('disabled')
on the item that was just changed, I think that would work. But, I'm not sure how to go about this.
Does anyone have any ideas?
Thanks!