Introduction: In this article I am going to share how to clear
textbox value on change of asp.net dropdownlist selection using jquery.
In previous articles I explained
how to Reset all asp.net or HTML controls placed on web form using jquery and Show jQuery notification pop up message box and hide after 5 seconds and Reset DropDownList value using jquery and Get dropdownlist selected item value, text and index using jquery and JQuery to enable disable all controls placed inside div based on dropdownlist selected value
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:
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..