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

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.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-02 02: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?

Pat
B3ea9ae043f9156a7f88159dcb6b2585?d=identicon&s=25 scottymac (Guest)
on 2006-04-02 03:48
(Received via mailing list)
Give this a try:
page.send :record, "document.getElementById('post_title').focus()"

--
View this message in context:
http://www.nabble.com/Focus-on-ajax-newly-created-...
Sent from the RubyOnRails Users forum at Nabble.com.
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-04-02 06:21
(Received via mailing list)
Surely you can just use...

page['post_title'].focus
This topic is locked and can not be replied to.