views:

33

answers:

2

I want to have a text value for a form like "search website.com..." but if the form has been submitted i want the query to appear- i dont know ruby idioms that well but i was think

<%= text_field_tag "q", params[:q] | "search website.com...." %>

is this correct?

A: 

That should work pretty well. The only thing I might add is that you should use a bit of javascript to check if it is the "default" string of "search website.com..." and if so, when a user clicks or focuses on the text box, you should clear the default string so that they don't have to do it themselves. Again, this should only be done on the default string, not if the user enters one.

Topher Fangio
see im taking a html file into a template file and the text field is- <input type="text" id="q" value="Search website.com" onfocus="if (this.value=='Search website.com') this.value = ''" class="swap_value" />
chris
@chris - That should work just fine. However, if you haven't checked out http://jQuery.com , you really should.
Topher Fangio
+3  A: 

That will work, but you should use || (logical OR operator) instead of | (bitwise OR).

Alex Reisner
+1 - Ah...can't believe I didn't catch that.
Topher Fangio