WordPress.org

Ready to get started?Download WordPress

Forums

Search Box Default Value (8 posts)

  1. DanMichel
    Member
    Posted 3 years ago #

    What would I do here to give my search box a default vallue of 'Search' then have it disappear when someone clicks it?
    <input type="text" value="' . get_search_query() . ' " name="s" id="s" class="textbox" />

  2. Gwyn
    Member
    Posted 3 years ago #

    I use this snippet:

    <form id="searchform" method="get" action="search.php">
    <input value="Search" name="s" id="s" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" type="text">
    </form>

    If you want to change the text, make sure you edit it in all 3 places

  3. DanMichel
    Member
    Posted 3 years ago #

    this is what i have now

    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    	<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
    	<input type="text" value="' . get_search_query() .  ' " name="s" id="s" class="textbox" />
    	<input type="submit" id="searchsubmit" value="'. esc_attr__('') .'" class="searchsubmit" />
    	</div>
    	</form>';
  4. DanMichel
    Member
    Posted 3 years ago #

    I'm getting an error http://d.pr/a4nX

  5. DanMichel
    Member
    Posted 3 years ago #

    actually, this is what i have

    <form id="searchform" method="get" action="search.php">
    <input class="textbox" value="Search" name="s" id="s" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" type="text">
    <input type="submit" id="searchsubmit" value="" class="searchsubmit" />
    </form>

    but it doesn't seem to work

  6. DanMichel
    Member
    Posted 3 years ago #

    http://pastebin.com/jDDXbg2U doesnt work, and the sidebar doesnt load

  7. Gwyn
    Member
    Posted 3 years ago #

    <form id="searchform" method="get" action="search.php">
    <input class="textbox" value="Search" name="s" id="s" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" type="text">
    <input type="submit" id="searchsubmit" value="" class="searchsubmit" />
    </form>

    On its own that should work (though the 'Go' button will have no text).

    If you're still using the whole $form = ... thing, then you'll need to escape out all the apostrophes between $form = ' and the closing '; by putting a \ immediately before each one.

  8. whatachamp
    Member
    Posted 3 years ago #

    Nice one gwynf, this is working a treat.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.