Forum: Ruby on Rails How to position cursor on first input 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.
sultan (Guest)
on 2009-03-20 21:03
(Received via mailing list)
It must be simple, but I haven't been able to figure it out.
Philip H. (Guest)
on 2009-03-20 21:24
(Received via mailing list)
> It must be simple, but I haven't been able to figure it out.

If it's the first form this would work:

<%= javascript_tag "$$('form input[type=text]').first().focus()" %>

Tweak as necessary to target the form/element in question...

-philip
Robert W. (Guest)
on 2009-03-21 04:20
Philip H. wrote:
>> It must be simple, but I haven't been able to figure it out.
>
> If it's the first form this would work:
>
> <%= javascript_tag "$$('form input[type=text]').first().focus()" %>

Also don't forget to include the Prototype scripts in the <head> section
to use the $$ method:

<%= javascript_include_tag :defaults %>
This topic is locked and can not be replied to.