Results 1 to 5 of 5

Thread: Input text in search box pre-search

  1. #1
    Join Date
    Feb 2007
    Posts
    5

    Default Input text in search box pre-search

    is there any way to do this?
    you know, the kinda thing where the word 'search' is in the input field prior to the user clicking in this field to enter a search?
    thanks in advance!

  2. #2
    Join Date
    Dec 2004
    Location
    Sydney
    Posts
    4,156

    Default

    To set the field value you can use some HTML.
    <input type="text" name="zoom_query" size="10" value="Your text here">

    But the real trick if clearing the field when the user clicks on it to enter their own search word and restoring the value if they don't enter anything.

    Code:
    <script type="text/javascript">
    function clickclear(thisfield, defaulttext) {
      if (thisfield.value == defaulttext) {
        thisfield.value = "";
      }
    }
     
    function clickrecall(thisfield, defaulttext) {
      if (thisfield.value == "") {
       thisfield.value = defaulttext;
      }
    }
    </script>
     
    <input type="text" name="zoom_query" size="10" value="Your text" 
    onclick=”clickclear(this, 'Your text')” onblur=”clickrecall(this,'Your text')” />

  3. #3
    Join Date
    Feb 2007
    Posts
    5

    Default Awesome

    Many thanks - great product by the way

  4. #4
    Join Date
    Aug 2011
    Posts
    5

    Default Input goes inside a form but loses functionality

    Doesn't the input have to be in a "form" to work properly? I can't get this javascript to work on my page so that the field appears with default text and disappears/reappears on user action. I just copied it from above. Here's my page:

    <html>
    <head>
    <title>You have reached a random place</title>
    <meta name="description" content="dogs and other farm animals"/>
    <meta name="keywords" content="albert,einstein,physics" />

    <script type="text/javascript">
    function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
    thisfield.value = "";
    }
    }

    function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == “”) {
    thisfield.value = defaulttext;
    }
    }
    </script>
    </head>

    <form method="get" action="http://www.jessiewilliams.com/search/search.php">
    <input type="text" name="zoom_query" size="10" value="Your text"
    onclick=”clickclear(this, ‘Your text’)” onblur=”clickrecall(this,’Your text’)”/>
    <input type="submit" value="Click and See"/>
    </form>

    <h1>This is a Test</h1>

    <body style="background-color:yellow;">

    <p>blah blah</p>
    <br />

    </body>
    </html>

  5. #5
    Join Date
    Dec 2004
    Location
    Sydney
    Posts
    4,156

    Default

    This question was answered twice via E-mail. Your HTML is invalid.

    For example, your <form> tag is between the <head> and < body> tag. Which isn't valid HTML. Nor is the use of reverse quotes, like in ‘Your text’

Posting Permissions

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