Hi,

> This works .. but my question is .. will this generate 100 events? So
> will my memory get filled with 100 on blurr events?
>
> Would it be the same if I just Even.subscribe 100 times?

You'll get one event fired at a time, because only one element can
lose focus at a time.

Depending on how you hook up the event handler, you may end up with
multiple copies of your event handler function, but you probably
haven't coded it that way. If you did this:

    $$('input').each(function(element) {
        element.observe('blur', function(event) {
            // Handle the blur event here
        });
    });

...you'd end up with 100 identical copies of your event handler
function, which isn't ideal. But more likely you did this:

    $$('input').invoke('observe', 'blur', function(event) {
        // Handle the blur event here
    });

...which means you only have one event handler function, which is
hooked up to 100 elements. (You can tell which element lost focus by
looking at `this` within the event handler; it'll be the element on
which the handler was registered.)

However, regardless of which of the above you use, under the covers
Prototype will create 100 helper functions because of the way it hooks
up event handlers. It's probably not a problem, but useful to know.

As Richard said, whenever you _can_, you want to use event bubbling to
avoid hooking 100s of elements. But as Walter said, 'blur' doesn't
bubble (except in buggy implementations).

If you have hundreds of elements and need to track focus, you probably
want to look at using a different event that *does* bubble so you
don't have hundreds of handlers. For a bubbling version of 'blur',
look at 'focusout' and 'deactivate'. IIRC, the former is supported by
most browsers other than IE6, and the latter is supported by IE6 (but
I don't have IE6 handy to test that). Quirksmode has some useful info
about these events (and test pages) here:
http://www.quirksmode.org/dom/events/blurfocus.html

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Jul 30, 10:51 am, Yozefff <[email protected]> wrote:
> Question ..
>
> Let's say I have 100 input fields, type = text. I want to put a onblur
> on all of them and pointing to the same function.
>
> So I've used
>
> $$("input") and invoke a blur.
>
> This works .. but my question is .. will this generate 100 events? So
> will my memory get filled with 100 on blurr events?
>
> Would it be the same if I just Even.subscribe 100 times?
>
> greets

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to