jokkesvin
Member
Posted 3 years ago #
Hey people :)
I'm having some difficulties with my search field. I'd like it to contain the word "search" as default. When the use clicks the field, it should disappear. I got that part working. The thing that's bothering me is this: When I type something in (i.e. "dog") and press enter to search, the search results come up and everything is fine, but the search field then reads "dogsearch".
I would like the search field to "reset" after a search and only contain the word "search". How can I accomplish this?
This is my current code:
<form method="get" id="searchform" action="<?php bloginfo('home');?>/">
<h4 class="search">
<input type="text" value="<?php echo wp_specialchars($s, 1); ?>søg" onblur="if(this.value == '') {this.value = 'søg';}" onfocus="if(this.value == 'søg') {this.value = '';}" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</h4>
</form>
jokkesvin
Member
Posted 3 years ago #
jokkesvin
Member
Posted 3 years ago #
I'm sure it's just a tiny little detail that needs to be added...
try
<form method="get" id="searchform" action="<?php bloginfo('home');?>/">
<h4 class="search">
<input type="text" value="" onblur="if(this.value == '') {this.value = 'søg';}" onfocus="if(this.value == 'søg') {this.value = '';}" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</h4>
</form>
jokkesvin
Member
Posted 3 years ago #
Thanks chaoskaizer, it kind of works. But when I'm using the code you suggested, the search field is empty whenever the page loads, and I want it to contain the word "søg" ("search" in Danish) at all times, unless the search field is clicked.
Is this not possible?
Thank for the code though - definitely better than before.
Doodlebug
Member
Posted 3 years ago #
Works fine for me.
Firefox / Windows.
jokkesvin
Member
Posted 3 years ago #
Okay I solved the problem by replacing this:
value="<?php echo wp_specialchars($s, 1); ?>søg"
with this:
value="søg"
But now I wonder what exactly this is for:
<?php echo wp_specialchars($s, 1); ?>
Do you think it somehow messes up my search now that it's gone?
Do you think it somehow messes up my search now that it's gone?
no its fine
http://blog.jokke-svin.dk/?s=42
jokkesvin
Member
Posted 3 years ago #
el_furioso
Member
Posted 3 years ago #
Exactly what I was looking for. Thanks! :)