In previous posts I explained change background of controls when validation fails, Change textbox background color in JavaScript, split the string, add fade in effect to page, Password strength jquery plugin examples and many articles relating to JQuery. Now I will explain how to change textbox background color on focus using JQuery in asp.net.
<script type="text/javascript">
$(document).ready(function()
{
$('INPUT[type="text"]').focus(function() {
$(this).addClass("focus");
});
$('INPUT[type="text"]').blur(function() {
$(this).removeClass("focus");
});
});
</script>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Change textbox background color on focus in jquery</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()
{
$('INPUT[type="text"]').focus(function() {
$(this).addClass("focus");
});
$('INPUT[type="text"]').blur(function() {
$(this).removeClass("focus");
});
});
</script>
<style type="text/css">
.focus {
border: 2px solid red;
background-color: #FEFED5;
}
</style>
</head>
<body>
<form id="form1"
runat="server">
<div>
<table>
<tr>
<td><b>Name:</b></td>
<td><asp:TextBox ID="txtName"
runat="server"/></td>
</tr>
<tr>
<td><b>FirstName:</b></td>
<td><asp:TextBox ID="txtfname"
runat="server"/></td>
</tr>
<tr>
<td><b>LastName:</b></td>
<td><asp:TextBox ID="txtlname"
runat="server"/></td>
</tr>
<tr>
<td><b>Location:</b></td>
<td><asp:TextBox ID="txtlocation"
runat="server"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnSubmit"
runat="server"
Text="Submit"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
|
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
1 comments :
Seems to work ok unless you have TextMode="Password". How do you get it to work in that case?