Ways of getting Dropdown list Selected Values.

Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 636
There are 2 ways to get DropDownList selected values through Javascript.

Suppose,we have a DropDownList as below:-

<asp:DropDownList ID="ddl_name_list" runat="server">
<asp:ListItem Text="Vishal" Value="1">Vishal</asp:ListItem>
<asp:ListItem Text="Rajesh" Value="2">Rajesh</asp:ListItem>

1st way:-
var ddl = document.getElementById('<%=ddl_name_list.ClientID%>');
var value = ddl.options[ddl.selectedIndex].value;

2nd way:-
var value = document.getElementById("<%= ddl_name_list.ClientID %>").value;

Comments or Responses

Login to post response