# How to position cursor on first input field?

**URL:** <https://www.ruby-forum.com/t/how-to-position-cursor-on-first-input-field/163480>\
**Category:** Rails\
**Created:** [March 20, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/how-to-position-cursor-on-first-input-field/163480 "2009-03-20T20:03:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 20, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/how-to-position-cursor-on-first-input-field/163480/1 "2009-03-20T20:03:48Z")

</div>

It must be simple, but I haven’t been able to figure it out.

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 20, 2009, 8:24pm UTC](https://www.ruby-forum.com/t/how-to-position-cursor-on-first-input-field/163480/2 "2009-03-20T20:24:20Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 21, 2009, 3:20am UTC](https://www.ruby-forum.com/t/how-to-position-cursor-on-first-input-field/163480/3 "2009-03-21T03:20:36Z")

</div>

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 section  
to use the $$ method:

\<%= javascript\_include\_tag :defaults %\>
