24 December, 2008

highlight text when text box field has focus

The following code is exact correct code

TextBox1.Attributes.Add("onFocus", "JavaScript:this.select();");

for additional

On page load event

TextBox1.Attributes.Add("onfocus", "javascript:return Highlight('" + TextBox1.ClientID + "');");


TextBox1.Attributes.Add("onblur", "javascript:return DeHighlight('" + TextBox1.ClientID + "');");

<script type="text/javascript" language="javascript">

function Highlight(control)
{
var mycontrol = document.getElementById(control);
mycontrol.className = 'Welcome';
}
function DeHighlight(control)
{
var mycontrol = document.getElementById(control);
mycontrol.className = 'Bye';
}