Support » Themes and Templates » Resetting text in search field after search

  • 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>
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter jokkesvin

    (@jokkesvin)

    Oh, this is by blog btw.

    Thread Starter jokkesvin

    (@jokkesvin)

    I’m sure it’s just a tiny little detail that needs to be added…

    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>

    Thread Starter jokkesvin

    (@jokkesvin)

    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.

    Works fine for me.

    Firefox / Windows.

    Thread Starter jokkesvin

    (@jokkesvin)

    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?

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

    no its fine

    http://blog.jokke-svin.dk/?s=42

    Thread Starter jokkesvin

    (@jokkesvin)

    Thanks chaoskaizer πŸ™‚

    Exactly what I was looking for. Thanks! πŸ™‚

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Resetting text in search field after search’ is closed to new replies.