Login Password text field values

I have a text field that I use for logging in users. Due to the design
of my site, I don’t have room to put the word “username” in front of the
text field so I’d like to actually display it inside the field and then
have the word clear when the user clicks on it.

How could I modify something like this

<%= text_field “user”, “login”, :size => 15 %>

to do that?


Vince W. wrote:


Hi Vince,

I think you need to use ‘:value=>…’ for this:
<%= text_field “user”, “login”, :value => ‘username’, :size => 15 %>

Hope this helps.

On 7/31/06, Mohit S. [email protected] wrote:

Hope this helps.

Rails mailing list
[email protected]

The value option is definitely required. Also if you want it to go
when the user clicks in it then you will need some JS. You will need to
give your username text_field an HTML id parameter so you can reference
in the JS. Somthing like

function clear_usernamed( dom_id ) {
if $( dom_id ).value == “username” {
$( dom_id ).value = “”;

and your field

<%= text_field “user”, “login”, :value => ‘username’, :size => 15,
=> "clear_username( ‘user_login’);’ %>

Then call this on the onFocus action for your username field. I’m not
exactly sure of the format for onFocus. :on_focus, :onFocus, ‘onFocus’
Unless someone else can help you’ll need to experiment.

If you really want to make it really nice you could include this in a
behaviour, but the basic case above should work.

Mohit S. wrote:

I think you need to use ‘:value=>…’ for this:
<%= text_field “user”, “login”, :value => ‘username’, :size => 15 %>

Hi Mohit,
It gets me 50% of the way there… all that’s left is clearing the field
when it’s selected (so people don’t have to manually erase ‘username’ to
enter their user name.

Is there any equivalent of an onfocus clear or anything for rails?



Here is the final text field:

<%= text_field "user", "login", :value => 'username', :size => 15 

,:class =>‘loginbox’, :onFocus => ‘clearDefault(this)’ %>

and the corresponding javascript:

Thanks guys!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs