开发者

dropdownlist selected index option not working with javascript

I am using an asp.net dropdownlist it contains 5 values the sample code is as follows

<asp:DropDownList ID="ddlSampledropdown" runat="server" Widt开发者_高级运维h="250px">
     <asp:ListItem Value="0" title="--Select--">--Select--</asp:ListItem>
     <asp:ListItem Value="1" title="Alpha">Alpha</asp:ListItem>
     <asp:ListItem Value="2" title="Bravo">Bravo</asp:ListItem>
     <asp:ListItem Value="3" title="Charlie">Charlie</asp:ListItem>
     <asp:ListItem Value="4" title="Delta">Delta</asp:ListItem>
     <asp:ListItem Value="5" title="Echo">Echo</asp:ListItem>
</asp:DropDownList>

I want to set the dropdownlist as disabled and set the selected text as alpha how can i do this with the help of a javascript in asp.net 2003

I made it as disabled but was unable to set the dropdownlist selected value


with JQuery, to select Alpha:

$("#ddlSampledropdown").val('1');

and to disable the control:

$("#ddlSampledropdown").attr("disabled", true);

sources:

Change the selected value of a drop-down list with jQuery

Disable drop down box on radio button click


Using classic Javascript, you may consider doing something like this. Note: obtain the correct client Id for your drop down.

var mydropdown= document.getElementById("ctl00_ctl00_<clientIdForDropdown>");
mydropdown.options[1].selected="selected";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜