Saturday, 22 March 2014

get dropdown value in jquery

The .val() method is primarily used to get the values of form elements such as input, select and textarea, And to get the text of the dropdown values by jquery need to use .text() method.
@Code snippet how to get Value of dropdown in Jquery
<head runat="server">
    <title>Validation by Javascript</title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#ddlvalues").change(function () {
                alert($("#ddlvalues option:selected").val()); //get Value of dropdown in Jquery
                alert($("#ddlvalues option:selected").text()); //get text of dropdown in Jquery
    <form id="form1" runat="server">
        <table width="60%" align="center">
                <td colspan="2" align="center">
                        Validation by Javascript</h1>
                <td align="right">
                    Get Value
                <td align="left">
                    <asp:DropDownList ID="ddlvalues" ClientIDMode="Static" runat="server">
                        <asp:ListItem Text="first" Value="1"></asp:ListItem>
                        <asp:ListItem Text="second" Value="2"></asp:ListItem>
                        <asp:ListItem Text="Third" Value="3"></asp:ListItem>
@Screen out put in Browser

No comments:

Post a Comment