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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    text input hint value not clearing onclick

    Having problems with a very simple script, I want the value of the text input to be cleared when the user clicks the box, but only if it is the default value, but it wont work.

    This is the function:
    Code:
    function clear()
    {
    var text = document.getElementByName('s').value;
    
    if(text == "Search Site...")
      {
      	document.getElementByName('s').value="";
      }
    }
    And this is the input:
    Code:
    <input type="text" size="9" name="s"  value="Search Site..." onclick="clear()"/>
    Any ideas?

    Thanks in advance.

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    You need to use the error console, which will tell you about a non-existent function.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    To auto-retore default text in a textbox:-

    Code:
    <input type = "text" name = "uname" id = "uname" value = "Name: "  onclick = "if (this.value == 'Name: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Name: ';" />
    <br>
    
    <input type = "text" name = "email" id = "email" value = "Email: "  onclick = "if (this.value == 'Email: ') this.value = '';"  onblur = "if (this.value == '') this.value = 'Email: ';" />


    Expecting the world to treat you fairly because you are good is like expecting the bull not to charge because you are a vegetarian.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    nerdydev (02-13-2013)

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts
    thanks Philip M, was looking for a way to do it in-line, thank you.


  •  

    Posting Permissions

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