Can't set the selected option for dropdown using JQuery
Posted on 2013-06-21
I have a web form that contains a textbox and a dropdown list. The dropdown list is disabled unless there is a value in the textbox when the page loads. This is done in the code behind. Once the page is loaded, I use JQuery to enable and disable the textbox based on whether there is data in the textbox. I have that working fine.
What I need to do is reset the selected option to the first option in the list which is my Choose prompt with a value of "". I can't seem to get the JQuery correct. Here is the dropdown definition:
<asp:DropDownList ID="ddPromotionReason" runat="server"
AppendDataBoundItems="True" CausesValidation="True" ClientIDMode="Static" Enabled="False">
<asp:ListItem Value="">-- Choose Promotion Reason --</asp:ListItem>
Here is the JQuery:
// Disable Promotion Reason DropDown if Promotion Date removed
// Remove option selected
$("#ddPromotionReason option[value='\"\"']").attr("selected", "selected");
Any help is greatly appreciated!