Pages

Wednesday 3 April 2013

How to get Dropdown Selected value using javascript in ASP.NET?

HTML
So first add an aspx page into your project & paste the below code for asp:dropdownlist under the form div section:
<asp:DropDownList ID="DropDownList1" runat="server" OnChange="javascript:GetDropDownValue()">
<asp:ListItem Value="1">C#</asp:ListItem>
<asp:ListItem Value="2">ASP</asp:ListItem>
<asp:ListItem Value="3">WPF</asp:ListItem>
<asp:ListItem Value="4">WCF</asp:ListItem>
<asp:ListItem Value="5">C++</asp:ListItem>
asp:DropDownList>
Javascript
Add javascript function in head tag
function GetDropDownValue()
{
var IndexValue = document.getElementById('<%=DropDownList1.ClientID %>').selectedIndex;
var SelectedVal = document.getElementById('<%=DropDownList1.ClientID %>').options[IndexValue].text;
alert(SelectedVal);
}
Output

No comments:

Post a Comment