How to get Id and value of dropdownlist of using Javascript ?


So many time we will get scenario to get Id and value of dropdownlist using Javascript in We can get like this

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

 <script type="text/javascript">

        function CountrySelect() {
            var dll = document.getElementById('<%=ddlCountry.ClientID %>');
            //For getting Text value of dropdownlist
            var mod = dll.options[dll.selectedIndex].text;
            //For getting Value of dropdownlist
            var mod1 = dll.options[dll.selectedIndex].value;

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
Country Name: 
    <asp:DropDownList ID="ddlCountry" runat="server">
        <asp:ListItem Value="0">Select</asp:ListItem>
        <asp:ListItem Value="1">Nepal</asp:ListItem>
        <asp:ListItem Value="2">India</asp:ListItem>
    <br />
    <asp:Button ID="Button1" runat="server" OnClientClick="CountrySelect();" Text="Submit" />


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.