Forums

Resetting text in search field after search (10 posts)

  1. jokkesvin
    Member
    Posted 3 years ago #

    Hey people :)

    I'm having some difficulties with my search field. I'd like it to contain the word "search" as default. When the use clicks the field, it should disappear. I got that part working. The thing that's bothering me is this: When I type something in (i.e. "dog") and press enter to search, the search results come up and everything is fine, but the search field then reads "dogsearch".

    I would like the search field to "reset" after a search and only contain the word "search". How can I accomplish this?

    This is my current code:

    <form method="get" id="searchform" action="<?php bloginfo('home');?>/">
    <h4 class="search">
    <input type="text" value="<?php echo wp_specialchars($s, 1); ?>s&oslash;g" onblur="if(this.value == '') {this.value = 's&oslash;g';}" onfocus="if(this.value == 's&oslash;g') {this.value = '';}" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </h4>
    </form>
  2. jokkesvin
    Member
    Posted 3 years ago #

    Oh, this is by blog btw.

  3. jokkesvin
    Member
    Posted 3 years ago #

    I'm sure it's just a tiny little detail that needs to be added...

  4. chaoskaizer
    Member
    Posted 3 years ago #

    try

    <form method="get" id="searchform" action="<?php bloginfo('home');?>/">
    <h4 class="search">
    <input type="text" value="" onblur="if(this.value == '') {this.value = 's&oslash;g';}" onfocus="if(this.value == 's&oslash;g') {this.value = '';}" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </h4>
    </form>
  5. jokkesvin
    Member
    Posted 3 years ago #

    Thanks chaoskaizer, it kind of works. But when I'm using the code you suggested, the search field is empty whenever the page loads, and I want it to contain the word "søg" ("search" in Danish) at all times, unless the search field is clicked.

    Is this not possible?

    Thank for the code though - definitely better than before.

  6. Doodlebug
    Member
    Posted 3 years ago #

    Works fine for me.

    Firefox / Windows.

  7. jokkesvin
    Member
    Posted 3 years ago #

    Okay I solved the problem by replacing this:

    value="<?php echo wp_specialchars($s, 1); ?>s&oslash;g"

    with this:

    value="s&oslash;g"

    But now I wonder what exactly this is for:

    <?php echo wp_specialchars($s, 1); ?>

    Do you think it somehow messes up my search now that it's gone?

  8. chaoskaizer
    Member
    Posted 3 years ago #

    Do you think it somehow messes up my search now that it's gone?

    no its fine

    http://blog.jokke-svin.dk/?s=42
  9. jokkesvin
    Member
    Posted 3 years ago #

    Thanks chaoskaizer :)

  10. el_furioso
    Member
    Posted 3 years ago #

    Exactly what I was looking for. Thanks! :)

Topic Closed

This topic has been closed to new replies.

About this Topic