Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Drop Down Option using jQuery

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>
like image 483
nasty Avatar asked Aug 01 '12 03:08

nasty


People also ask

How to disable input Dropdown in HTML?

To disable auto-completion of input fields, use the HTML attribute autocomplete with a value set to off .

How do I turn off multi select dropdown?

multiselect('disable'); will disable the selector (stored in the variable $widget ). And by replacing disable with enable you can enable it. So just run the function with the correct disable/enable setting and you can do it based on any condition.


1 Answers

$("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);
});
like image 116
thecodeparadox Avatar answered Sep 16 '22 20:09

thecodeparadox