[resolved] Search form value (3 posts)

  1. noelgreen
    Posted 7 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
    Posted 7 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
    Posted 7 years ago #

    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