WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Search form value (3 posts)

  1. noelgreen
    Member
    Posted 6 years ago #

    How can I replace the:
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s"/>

    for the search with:
    <input type="text" value="Enter City, State or Zipcode" name="s" id="s"/>

    And it still work as a search?

    Basically I want that text to disappear when someone selects the input box.

    I tried this and it didn't work:
    <input type="text" value="<?php the_search_query('Enter City, State or Zipcode'); ?>" name="s" id="s"/>

    Any ideas?

  2. Jeremy Clark
    Moderator
    Posted 6 years ago #

    I've used this little bit of code for my search box. This will show your text if the user hasn't selected the box but if the user selects then moves focus away from the box the the text is put back.

    <input id="s" type="text" onblur="if(this.value == '') {this.value = 'Enter City, State or Zipcode';}" onfocus="if(this.value == 'Enter City, State or Zipcode') {this.value = '';}" value="Enter City, State or Zipcode" name="s"/>

  3. noelgreen
    Member
    Posted 6 years ago #

    Thanks!
    I didn't see your reply, but had found basically the same thing!

    <input type="text" value="<?php echo $search; ?>" name="s" id="s" onfocus="if (this.value == '<?php echo $search; ?>') {this.value = '';}" onblur="if(this.value == '') {this.value = '<?php echo $search; ?>';}" style="width: 250; margin: 0px 0px 0px 0px; padding: 4px; color: #666;" tabindex="1"/>

    Thanks again! That works great. :)

Topic Closed

This topic has been closed to new replies.

About this Topic