Focus on ajax newly-created form element

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?


Give this a try:
page.send :record, “document.getElementById(‘post_title’).focus()”

View this message in context:
Sent from the RubyOnRails Users forum at

Surely you can just use…


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs