Topic: Textfield with text by default a la Google search bar

I am looking to make a textfield like the Google search bar builtin to Firefox and IE. I want it to display "Search" by default, but once the field is given focus, it is blank.

What's the best way to do this? Is there a rails way?

Re: Textfield with text by default a la Google search bar

You'll have to use Javascript.

Basically, give the input field an initial value (value="whatever"), and then an onfocus attribute that uses Javascript to set the value to blank.  I'm not sure exactly how to implement that, but hopefully it'll set you in the right direction.

Re: Textfield with text by default a la Google search bar

This was the best solution I could come up with. What is a better way to do this? At the very least, I would like to get the javascript out of the input tag.

:onBlur => "document.getElementById('query').value = 'Search'",
:onFocus => "document.getElementById('query').value = ''"