Forum: Ruby on Rails Focus on ajax newly-created form element

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2006-04-02 04:35
(Received via mailing list)
I have an ajax method that creates a new form.  I want one of the
input boxes to be focused when the form gets displayed.  So in my
inline RJS I have

page << "document.getElementById('post_title').focus();"

The input box is being created with
<%= text_field 'post', 'title' %>, so the ID should end up being
'post_title' - FireFox's DOM inspector confirms it.

However the text field isn't getting focused, so I must be doing
something wrong.  Any advice?

scottymac (Guest)
on 2006-04-02 05:48
(Received via mailing list)
Give this a try:
page.send :record, "document.getElementById('post_title').focus()"

View this message in context:
Sent from the RubyOnRails Users forum at
Jonathan V. (Guest)
on 2006-04-02 08:21
(Received via mailing list)
Surely you can just use...

This topic is locked and can not be replied to.