...

View Full Version : Change the color of the value attribute



joshua7
04-26-2008, 05:26 AM
Is it possible to change the color of the value attribute?
I've noticed that some sites have default text set on text fields in gray color.
When you click on them the text disappears and the characters you type are black.

How is this accomplished?

rangana
04-26-2008, 05:38 AM
See if this basic example help ;)


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload = function()
{
var myinput = document.getElementById('squery');
myinput.style.color='#aaa';
myinput.onfocus = function()
{
this.style.color='#222';
this.value=(this.value=='Search Here...')?'':this.value;
}
myinput.onblur= function()
{
if(this.value==''||this.value==null)
{this.value='Search Here...';this.style.color='#aaa';}
else{this.value;}
}
}
</script>
</head>
<body>
<input type="text" id="squery" value="Search Here..." >
</body>
</html>

joshua7
04-26-2008, 06:32 AM
That is perfect. Thanks so much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum