Rails: Focus textbox on page load

From FVue
Jump to: navigation, search

Problem

Once a page is loaded, I want to give focus to a textbox.

Environment

  • rails-3.0.6

Solution

...
<%= f.text_field :email, :value => 'E-mail', 
  :onfocus => "if (this.value == this.defaultValue) this.select()" %>
...
<%= javascript_tag "$(document).ready(function() { $('#email').focus(); })" %>
...

Comments

blog comments powered by Disqus