Reading ASP.NET drop down values using JQuery

ASP.NET Drop down values

From the below example, we can able to get the value from the drop down list select item using jquery.



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
    </title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#txtLanguage').hide();

            $('#ddlTeste').change(function () {
                var txtLanguage = $('#txtLanguage');
                var testvalues = $("#ddlTeste option:selected").text();
                if (testvalues) {
                    txtLanguage.show();
                    txtLanguage.val(testvalues);
                }
                else
                    txtLanguage.hide();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="ddlTeste" runat="server" >
    <asp:ListItem Value=""></asp:ListItem>
    <asp:ListItem Value="2">value 1</asp:ListItem>
    <asp:ListItem Value="3">value 2</asp:ListItem>
    <asp:ListItem Value="4">value 3</asp:ListItem>
    <asp:ListItem Value="5">value 4</asp:ListItem>
</asp:DropDownList>
        <asp:TextBox ID="txtLanguage" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>


output


 
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar