Forum: Rails Spinoffs (closed, excessive spam) How to fire on onfocus ?

57564570dcbfeb09e90c3fb913a7daf4?d=identicon&s=25 mocambo (Guest)
on 2008-06-15 05:15
(Received via mailing list)
I have on the page several text input tags. How to find which input
tag focused ?
Or how to observe all input tags at once ?
I've tried:

Event.observe($('divID').getElementsByTagName('input'), 'focus',
function(event) { } ); // invalid parameter

and

Event.observe(document.body, 'focus', function(event) { } ); // dont
fire at all

and

$('divID').getElementsByTagName('input').each( function(content) {
  Event.observe(content, 'focus', function(event) { } );
});

with no ant result. Hope you catch my logic !
57564570dcbfeb09e90c3fb913a7daf4?d=identicon&s=25 mocambo (Guest)
on 2008-06-15 06:10
(Received via mailing list)
OK, solved for now:

$('divID').select('input', '[type="text"]').each( function(e) {
  Event.observe(e, 'focus', function(event) { });
});

Only problem still occur:

select gives me all 'input' elements but needed only those with
type="text". What wrong above ?
57564570dcbfeb09e90c3fb913a7daf4?d=identicon&s=25 mocambo (Guest)
on 2008-06-15 06:34
(Received via mailing list)
My mistake ! Solved !

$('divID').select('input[type=text]').each( function(e) {
        Event.observe(e, 'focus', function(event) { });
});

Thank You ! :)
F1fcf834ddad415f60d29c87cc10d4d4?d=identicon&s=25 kangax (Guest)
on 2008-06-15 16:57
(Received via mailing list)
You might find #invoke [1] useful in this case:

$('divId').select('input[type=text]').invoke('observe', 'focus',
function(e) { ... });

[1] http://prototypejs.org/api/enumerable/invoke

- kangax
57564570dcbfeb09e90c3fb913a7daf4?d=identicon&s=25 mocambo (Guest)
on 2008-06-16 01:55
(Received via mailing list)
Thanks for invoke() ! :)
This topic is locked and can not be replied to.