Reading ASP.NET drop down values using JQuery

  Uncategorized

Reading ASP.NET drop down values 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:-

1,857 thoughts on - Reading ASP.NET drop down values using JQuery

LEAVE A COMMENT