Home » Forum
  • If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Input text in search box pre-search

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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')” />

    Comment


    • #3
      Awesome

      Many thanks - great product by the way

      Comment


      • #4
        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>

        Comment


        • #5
          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’

          Comment

          Working...
          X