Support » How-To and Troubleshooting » [Resolved] Search form value

[Resolved] Search form value

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Jeremy Clark



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

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Search form value’ is closed to new replies.