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
Solution 2:
Working demohttp://jsfiddle.net/BYkVW/orhttp://jsfiddle.net/BYkVW/1/
Hope it helps the needs :)
code
$("#field_0_1 option[value='- Sold Out -']").attr('disabled','disabled');
or
$("#field_0_1 option[value='- Sold Out -']").prop('disabled','disabled');
working image
Solution 3:
functionlockDownDropDownList(ddlName) {
ddlName = "#" + ddlName;
var chosenValue = $(ddlName).val();
var downDownListItems = $(ddlName).children('option').map(function (i, e) {
return e.value || e.innerText;
}).get();
downDownListItems.forEach(function (item) {
if (item != chosenValue)
{
$("select option[value*='" + item + "']").prop('disabled', true);
}
});
}
Solution 4:
Here i have done solution for above query. demo link as below:
Demo:http://codebins.com/bin/4ldqp92
HTML:
<selectid="field_0_1"class="text_select"name="field_0_1"onChange=""><optionvalue="">
- Preferred Time -
</option><optionvalue="- Sold Out -">
- Sold Out -
</option><optionvalue="2:30 - 4:00pm">
2:30 - 4:00pm
</option></select><selectid="field_0_2"class="text_select"name="field_0_2"onChange=""><optionvalue="">
- Preferred Time -
</option><optionvalue="- Sold Out -">
- Sold Out -
</option><optionvalue="2:30 - 4:00pm">
2:30 - 4:00pm
</option></select><selectid="field_0_3"class="text_select"name="field_0_3"onChange=""><optionvalue="">
- Preferred Time -
</option><optionvalue="- Sold Out -">
- Sold Out -
</option><optionvalue="2:30 - 4:00pm">
2:30 - 4:00pm
</option></select>
JQuery:
$(function() {
$("select").click(function() {
$(this).find("option[value*='Sold Out']").prop("disabled", true);
});
});
Solution 5:
$("#ddlList option[value='jquery']").attr("disabled","disabled");
Post a Comment for "Disable Drop Down Option Using Jquery"