Forum: Ferret default text in search text field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dfe5426733b8efd9240566b60c17f736?d=identicon&s=25 Makoto G. (makotogim)
on 2010-07-01 11:10
Hello,

I am trying to figure out how I can introduce a default text in my
searchbox that is removed automatically when the user tries to write
something.

Is this possible to do it with some kind of ferret command? The only way
I can find I can do it is with some javascript code.

Thanks in advance

Makoto
4b8e6b26c1aeaacbf9da8cc7aec003de?d=identicon&s=25 Veera S. (veeraa2003)
on 2010-09-22 09:05
Makoto Gim wrote:
> Hello,
>
> I am trying to figure out how I can introduce a default text in my
> searchbox that is removed automatically when the user tries to write
> something.
>
> Is this possible to do it with some kind of ferret command? The only way
> I can find I can do it is with some javascript code.
>
> Thanks in advance
>
> Makoto

Yes you have to use JS code to make it simpler and faster.


<input type="text" value="Search here..." onclick="clickclear(this,
'Search here...')" onblur="clickrecall(this, 'Search here...')"
name="search_term">

<script>
function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
  thisfield.value = "";
  }
}

function clickrecall(thisfield, defaulttext) {
  if (thisfield.value == "") {
  thisfield.value = defaulttext;
  }
}
</script>


--
Regards,

T.Veerasundaravel.
http://tinyurl.com/25vma7h
@veerasundaravel
Dfe5426733b8efd9240566b60c17f736?d=identicon&s=25 Makoto G. (makotogim)
on 2010-09-24 00:07
Hello Veera,

Thanks a lot, it worked perfectly!!!


regards

@makotogim

Veera Sundaravel wrote:
> Makoto Gim wrote:
>> Hello,
>>
>> I am trying to figure out how I can introduce a default text in my
>> searchbox that is removed automatically when the user tries to write
>> something.
>>
>> Is this possible to do it with some kind of ferret command? The only way
>> I can find I can do it is with some javascript code.
>>
>> Thanks in advance
>>
>> Makoto
>
> Yes you have to use JS code to make it simpler and faster.
>
>
> <input type="text" value="Search here..." onclick="clickclear(this,
> 'Search here...')" onblur="clickrecall(this, 'Search here...')"
> name="search_term">
>
> <script>
> function clickclear(thisfield, defaulttext) {
>   if (thisfield.value == defaulttext) {
>   thisfield.value = "";
>   }
> }
>
> function clickrecall(thisfield, defaulttext) {
>   if (thisfield.value == "") {
>   thisfield.value = defaulttext;
>   }
> }
> </script>
>
>
> --
> Regards,
>
> T.Veerasundaravel.
> http://tinyurl.com/25vma7h
> @veerasundaravel
This topic is locked and can not be replied to.