Results 1 to 3 of 3

Thread: Empty value of textbox once active

  1. #1
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Empty value of textbox once active

    I want to have a value in a textbox so that the user can see what needs to be entered. When the user selects the box to start entering details I want the it to empty. I have seen this used many times but don't know how this is achieved?

    Many thanks

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Please do not cross post.


    See if this basic example helps:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var inp=document.getElementById('inp'), // Set the input element's ID.
    text='Search...'; // Default input text's value. This should match on the value of your value attribute.
    inp.onfocus = function()
    	{this.style.color='#222';this.value=(this.value==text)?'':this.value;}
    inp.onblur= function()
    	{
    	if(this.value=='')
    		{
    		this.value=text;
    		this.style.color='#aaa';
    		}
    	else this.value;
    	}
    }
    </script>
    <input type="text" value="Search..." id="inp" style="color:#aaa;">
    Last edited by jscheuer1; 07-31-2008 at 05:34 PM. Reason: only one post required after merge of thread
    Learn how to code at 02geek

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

  3. #3
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That works brilliantly!! Thankyou

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
  •