Results 1 to 3 of 3

Thread: text box description

  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default text box description

    HTML Code:
    <html>
    <head>
    <title>txtbox</title>
    <script type="text/javascript">
    function blank(a) 
    	{ 
    		if(a.value == a.defaultValue) a.value = "";
    	}
    function fill(a)
    	{
    		if(a.value == "") a.value = a.defaultValue;	
    	}
    </script>
    </head>
    <body>
    <form name="em" action="#" method="post">
    <input type="text" value="Enter your email" onfocus="blank(this)" onblur="fill(this)" />
    </form>
    </body>
    </html>
    i want to blank textbox on focus and then again fill the default value on blur, this code is working fine but that default text in the textbox is of same color which when we write something in the textbox, i want the default text should be of different color like #CCC and when we insert text it should be of #000 color, i tried define the text color of textbox but then both text color are showing same, any help

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <html>
    <head>
    <title>txtbox</title>
    <script type="text/javascript">
    
    function blank(a){
     if(a.value == a.defaultValue){
      a.value = "";
      a.style.color='green';
     }
    }
    
    function fill(a){
     if(a.value == ""){
      a.value = a.defaultValue;
      a.style.color='red';
     }
    }
    
    </script>
    </head>
    <body>
    <form name="em" action="#" method="post">
    <input type="text" value="Enter your email" onfocus="blank(this)" onblur="fill(this)" />
    </form>
    </body>
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    ankush (02-04-2012)

  4. #3
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    thanks that's what i want...onLoad color was black but i fixed it..
    thanks for your help

Bookmarks

Posting Permissions

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