I want to disable the dropdown list item using jquery. The index value is -1 and the value is ------- Internal -------. I tried below syntaxes one by one(The solutions were the answers for similar questions). None of them are working. Iam using IE8.
var value="------- Internal -------";
$("[id*='ChildOrganizationDropDownList'] option[value=" + value + "]").prop('disabled','disabled');
$("#ChildOrganizationDropDownList option[value=" + value + "]").prop('disabled','disabled');
$("[id*='ChildOrganizationDropDownList']").option('------- Internal -------').prop('disabled',true);
$("id*='ChildOrganizationDropDownList' option[value='------- Internal -------']").prop('disabled','disabled');
$("[id*='ChildOrganizationDropDownList']").option("[value*='------- Internal -------']").prop('disabled', true);
$("[id*='ChildOrganizationDropDownList']").attr("disabled",$(_this.CustomerNameDropDownList).find("option[value='------- Internal -------']"));
Designer : Aspx
<div class="selectionControls">
<asp:CheckBox ID="chkSubcontracting" runat="server" Text="Subcontracting" Enabled="true" />
<asp:HiddenField ID="SubcontractingHiddenField" runat="server" />
<div class="subSelectionControl" id="AllowSubcotractingSelection" style="display: none;">
<div class="subContractingControls">
Parent BU:
<span>
<div class="subContractingControls">
Supplier <em class="mandatoryIndicator">*</em>:
<span>
<asp:DropDownList ID="ChildOrganizationDropDownList" runat="server" Width="200px" />
<asp:HiddenField ID="IxChildOrganizationHiddenField" runat="server" />
</span>
</div>
</div>
</div>
Aspx.cs
public Dictionary<int, string> ChildOrganizations
{
set
{
var result = value;
result.Add(0, "Select Supplier");
ChildOrganizationDropDownList.DataSource = result;
ChildOrganizationDropDownList.DataTextField = "value";
ChildOrganizationDropDownList.DataValueField = "key";
ChildOrganizationDropDownList.DataBind();
ChildOrganizationDropDownList.SelectedValue = "0";
}
}
The drop-down is used to create a list of items that need to select an element. We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element.
How do you enable disable a dropdown based on value in another dropdown in jQuery? val() == “ “) { $(“#ddl2”). prop(“disabled”, true); } else $(“#ddl2”). prop(“disabled”, false); }); }); The above code will disable the “ddl2” dropdown on select of a particular value in first dropdown.
JQuery code ready(function($) { var $select = $('#choose'), name = $select. prop('name'), $form = $select. parent('form'); //store the name in the data attribute $select. data('original-name', name); $('#toggle').
Set the attribute disabled = "disabled" in the <option> element to make the custom select menu option disable.
I used each
and it worked for me: https://jsfiddle.net/pz9curkb/1/
<select id="ChildOrganizationDropDownList">
<option value="Default">Default</option>
<option value="A">A</option>
<option value="B">------- Internal -------</option>
<option value="E">E</option>
</select>
$("#ChildOrganizationDropDownList option").each(function(){
if($(this).text() === "------- Internal -------"){
this.disabled = true;
}
});
Please note in this solution I used this instead of $(this), which means I used disabled option provided by javascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With