• 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" />

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

    Thread Starter DanMichel

    (@danmichel)

    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>';
    Thread Starter DanMichel

    (@danmichel)

    I’m getting an error https://d.pr/a4nX

    Thread Starter DanMichel

    (@danmichel)

    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

    Thread Starter DanMichel

    (@danmichel)

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

    <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.

    Nice one gwynf, this is working a treat.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Search Box Default Value’ is closed to new replies.