Focus on ajax newly-created form element


#1

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


#2

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-form-element-t1381109.html#a3709254
Sent from the RubyOnRails Users forum at Nabble.com.


#3

Surely you can just use…

page[‘post_title’].focus