Thursday, January 10, 2008

change Background Color of onfocus of HTML control


Change Background Color of HTML control:onfocus of any control bgcolor of the control should change & onblur it should again become white.this is the code


<script type="text/javascript" language="javascript">
function set()
{

for (i=0; i {

if (document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password" || document.forms[0].elements[i].type=="textarea")
{
document.forms[0].elements[i].onfocus=function() {this.style.backgroundColor='#E3E0DB';};
document.forms[0].elements[i].onblur=function() {this.style.backgroundColor='#ffffff';};
}


if (document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password" || document.forms[0].elements[i].type=="textarea")
{
if(document.forms[0].elements[i].value="")
document.forms[0].elements[i].focus();
}

}
}

</script>

No comments: