Bob Smith
2010-Jul-23 22:15 UTC
I''m trying to get started with AJAX and having a problem..
I''m trying to set the focus to the first (and only} field on a search form and having no luck. From searching with google, I came up with: javascript_tag("Event.observe(window, ''load'', function() { var firstForm = $A(document.getElementsByTagName(''search''))[0]; Form.focusFirstElement(firstForm);} );") no response, though. Please help Bob -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Jul-23 22:32 UTC
Re: I''m trying to get started with AJAX and having a problem..
On Fri, Jul 23, 2010 at 3:15 PM, Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m trying to set the focus to the first (and only} field on a search > form and having no luck.> javascript_tag("Event.observe(window, ''load'', function() { > var firstForm = $A(document.getElementsByTagName(''search''))[0];For one thing, there is no HTML tag named "search"; you''re probably looking for an "input" ... :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bob Smith
2010-Jul-30 05:02 UTC
Re: I''m trying to get started with AJAX and having a problem..
Found the answer. I was making it much too complicated.. $("search").focus(); did just fine Bob On Jul 23, 6:15 pm, Bob Smith <bsm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m trying to set the focus to the first (and only} field on a search > form and having no luck. > From searching with google, I came up with: > > javascript_tag("Event.observe(window, ''load'', function() { > var firstForm = $A(document.getElementsByTagName(''search''))[0]; > Form.focusFirstElement(firstForm);} );") > > no response, though. Please help > > Bob-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bob Smith
2010-Aug-19 18:24 UTC
Re: I''m trying to get started with AJAX and having a problem..
or <%= javascript_tag(''$("search").focus();'') %> as part of a view.. Bob On Jul 30, 1:02 am, Bob Smith <bsm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Found the answer. I was making it much too complicated.. > > $("search").focus(); > > did just fine > > Bob > > On Jul 23, 6:15 pm, Bob Smith <bsm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m trying to set the focus to the first (and only} field on a search > > form and having no luck. > > From searching with google, I came up with: > > > javascript_tag("Event.observe(window, ''load'', function() { > > var firstForm = $A(document.getElementsByTagName(''search''))[0]; > > Form.focusFirstElement(firstForm);} );") > > > no response, though. Please help > > > Bob-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-19 18:38 UTC
Re: I''m trying to get started with AJAX and having a problem..
Bob Smith wrote:> or > > <%= javascript_tag(''$("search").focus();'') %> > > > as part of a view.. > > > BobBut never do that. JavaScript works best when it''s in separate files, not mixed with HTML. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.