Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get the focus for the textboxes during the entry. If i click to enter the data in textbox. That textbox get the focus and change color like white to black. Please can you help me?

Thank you,

Regards,
Snageetha
Posted

ASP.NET
<head>

<script type="text/javascript">

  function highlight(obj) {
            obj.style.backgroundColor = "Green";
  }
  function clearHighlight(obj) {
            obj.style.backgroundColor = "";
  }
</script>
</head>
<body>
<asp:textbox id="TextBox1" onfocus="highlight(this)" onblur="clearHighlight(this)" runat="server" >
</body>
 
Share this answer
 
v2
Add a css function as
C#
.focusfld
{
    background-color: #FFFFCC;
}


then add its reference in aspx page like:
HTML
<link href="Style/StyleSheet.css" rel="stylesheet" type="text/css" />


Write a Javacript funtion in aspx as:
C#
function Fun1(ctrl)
    {    
        ctrl.className = 'focusfld';
    }

and in the pageLoad() add:
C#
TextBox1.Attributes.Add("onFocus", "Fun1(this)");
 
Share this answer
 
Change Textbox/Input background color on focus[^] is a neat little article that should solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900