When you put up a page with a form on it and the top item is a text field it would be nice to have that field already focused instead of forcing the user to click in it before they start typing. Is there a rails (i.e. probably Prototype) way of giving focus to a field? I did some searching and found nothing. thanks, jp P.S. I''m on a Mac. Perhaps a winoze and/or unix automatically gives focus to the first text field in a form? -- Posted via http://www.ruby-forum.com/.
Jeff Pritchard wrote:> Is there a > rails (i.e. probably Prototype) way of giving focus to a field? I did > some searching and found nothing. > > thanks, > jp > > P.S. I''m on a Mac. Perhaps a winoze and/or unix automatically gives > focus to the first text field in a form?It''s a javascript thing, prototype makes it shorter though: $(''id_of_item_to_focus'').focus(); Win/linux don''t do this automatically. phil
> $(''id_of_item_to_focus'').focus(); > > Win/linux don''t do this automatically.what are you saying? safari auto-focuses the first text field and firefox doesnt? a line of greasemoneky can solve that..
carmen wrote:>> $(''id_of_item_to_focus'').focus(); >> >> Win/linux don''t do this automatically. >> > > what are you saying? safari auto-focuses the first text field and firefox doesnt? a line of greasemoneky can solve that..Not sure I understand what you are saying... the OP said:> P.S. I''m on a Mac. Perhaps a winoze and/or unix automatically gives > focus to the first text field in a form?I was just saying you can''t count on that on the other platforms either. That''s mostly FF and IE, which don''t auto-focus (at least not out of the box). cheers, phil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/f54da44e/attachment.html
Phillip Kast wrote:> carmen wrote: > ... > the OP said: >> P.S. I''m on a Mac. Perhaps a winoze and/or unix automatically gives >> focus to the first text field in a form? > > I was just saying you can''t count on that on the other platforms either. > That''s mostly FF and IE, which don''t auto-focus (at least not out of the > box). > > cheers, > philThanks guys. Sorry if I worded it poorly. I run a mac and Safari does not do this automagically. I didn''t take the time to start up Parallels and see if Windoze does it or not. I''ll try the one liner you suggested and see if it does the trick. thanks, jp -- Posted via http://www.ruby-forum.com/.
you could put this in your application.js //focuses on the first element on a page Event.observe(window, ''load'', function() { var e = $A(document.getElementsByTagName(''*'')).find(function(e) { return (e.tagName.toUpperCase() == ''INPUT'' && (e.type == ''text'' || e.type == ''password'')) || e.tagName.toUpperCase() == ''TEXTAREA''; }); if (e) e.focus(); }); On 7/23/06, Jeff Pritchard <jp@jeffpritchard.com> wrote:> Phillip Kast wrote: > > carmen wrote: > > ... > > the OP said: > >> P.S. I''m on a Mac. Perhaps a winoze and/or unix automatically gives > >> focus to the first text field in a form? > > > > I was just saying you can''t count on that on the other platforms either. > > That''s mostly FF and IE, which don''t auto-focus (at least not out of the > > box). > > > > cheers, > > phil > > Thanks guys. Sorry if I worded it poorly. I run a mac and Safari does > not do this automagically. I didn''t take the time to start up Parallels > and see if Windoze does it or not. > > I''ll try the one liner you suggested and see if it does the trick. > > thanks, > jp > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Phillip Kast wrote:> It''s a javascript thing, prototype makes it shorter though: > > $(''id_of_item_to_focus'').focus(); > > Win/linux don''t do this automatically. > > > philWhere do I put that code? Here''s the form I want to have autofocused: <%= text_field ''menu_item'', ''name'' %> Do I put it in the view page? I''d appreciate your help. Thanks. Chris -- Posted via http://www.ruby-forum.com/.