Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Change the color of the value attribute

    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?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    See if this basic example help
    Code:
    <!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>
    Last edited by rangana; 04-26-2008 at 05:44 AM.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    joshua7 (04-26-2008)

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    That is perfect. Thanks so much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •