Disable Drop Down Option using jQuery

nasty picture nasty · Aug 1, 2012 · Viewed 67.2k times · Source

I need to disable options with value "- Sold Out -" in a list of dynamic drop down menus. How can I do this easily with jQuery? Below is the HTML

<select id="field_0_1" class="text_select" name="field_0_1" onChange="">
<option value="">- Preferred Time -</option>
<option value="- Sold Out -">- Sold Out -</option>
<option value="2:30 - 4:00pm">2:30 - 4:00pm</option>
</select>
<select id="field_0_2" class="text_select" name="field_0_2" onChange="">
<option value="">- Preferred Time -</option>
<option value="- Sold Out -">- Sold Out -</option>
<option value="2:30 - 4:00pm">2:30 - 4:00pm</option>
</select>
<select id="field_0_3" class="text_select" name="field_0_3" onChange="">
<option value="">- Preferred Time -</option>
<option value="- Sold Out -">- Sold Out -</option>
<option value="2:30 - 4:00pm">2:30 - 4:00pm</option>
</select>

Answer

thecodeparadox picture thecodeparadox · Aug 1, 2012
$("select option[value*='Sold Out']").prop('disabled',true);
        ​

Demo

According to edit

$('#previous_select').on('change', function() {
   // after creating the option
   // try following
   $("select option[value*='Sold Out']").prop('disabled',true);
});