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.
55cfa29d393bc3cf2a1f2d373c85126e?d=identicon&s=25 sultan (Guest)
on 2009-03-20 20:03
(Received via mailing list)
It must be simple, but I haven't been able to figure it out.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-03-20 20: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
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2009-03-21 03:20
Philip Hallstrom 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.