jQuery to clear Asp.Net textbox based on dropdownlist selected item change

Introduction: In this article I am going to share how to clear textbox value on change of asp.net dropdownlist selection using jquery.

jQuery to Clear Asp.Net textbox  based on dropdownlist selected item change


Implementation: Let’s create a demo page for demonstration purpose.

HTML Source
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        function clearSearchKey() {
            $('#<%=txtSearchKey.ClientID%>').val('');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <fieldset style="height: 100px; width: 405px;">
                <legend>Clear Textbox based on DropDownList selection change</legend>
                <table>
                    <tr>
                        <td>Search By:<asp:DropDownList ID="ddlSearchBy" onchange="clearSearchKey();" runat="server">
                            <asp:ListItem Value="1" Text="Name"></asp:ListItem>
                            <asp:ListItem Value="2" Text="Code"></asp:ListItem>
                            <asp:ListItem Value="3" Text="Mobile No"></asp:ListItem>
                        </asp:DropDownList></td>
                        <td>
                            <asp:TextBox ID="txtSearchKey" runat="server"></asp:TextBox></td>
                        <td>
                            <asp:Button ID="btnSearch" runat="server" Text="Search" /></td>
                    </tr>
                </table>
            </fieldset>
        </div>
    </form>
</body>

</html>

Now over to you:
"A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..