Hi Jay,

> > Is it really necessary to use old DOM0-style event handlers (the
> > attribute on the tag) and modern event attachment in the same app?
>
> Sigh.. I absolutely agree with you 100% on this. However, I do not
> have control over how this is.

Yeah, we've all had that problem. :-)

What is the actual goal?  To attach a handler to the submit button
that fires before the one attached to the onclick, and (in some cases)
prevents the onclick from happening?  Because if it's that, you can
probably grab the DOM0 handler and then disconnect it:

* * * *
// At load time; here it's in a dom:loaded but whatever
document.observe("dom:loaded", function() {
    var btnGo;
    var dom0handler;

    // Get the submit button
    btnGo = $('btnGo');

    // Grab its current DOM0 handler
    dom0handler = btnGo.onclick;

    // Clear it
    btnGo.onclick = '';

    // Hook up your handler
    btnGo.observe('click', function(event) {
        var rv;

        alert("Your logic goes here");

        if (/* whatever decides whether to fire the old handler */) {
            // Chain to the DOM0 handler, if any
            if (Object.isString(dom0handler)) {
                rv = eval(dom0handler);
            }
            else if (Object.isFunction(dom0handler)) {
                rv = dom0handler(event);
            }
            if (!Object.isUndefined(rv) && !rv) {
                // Handler returned something false-y, cancel
                event.stop();
            }
        }
    });
});
* * * *
(Also on Pastie: http://pastie.org/420790)

Obviously you''ll want to make sure you satisfy the DOM0 handler's
expectations; the above just passes in the Prototype event object, but
doesn't set 'this' or anything like that.  You'll have to look at the
DOM0 handler to see what it's expecting.  The above *does* check for a
return value and, if found and if false-y, stops the event -- that's
typically what returning false from a DOM0 means.  This is not tested
code, although it worked okay on first glance on the browsers I tried
-- FF3, Opera9, IE7, Safari3, Chrome1 (all on Windows).

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Mar 19, 7:08 am, Jay <[email protected]> wrote:
> > I don't think input elements have a submit event.  Form elements do.
> > So that would be step one. :-)
>
> Ah.. you're right. I did ('myinput').observe('click', foofunc);  not
> 'submit'.
> Thanks for catching this. So I'm basically adding another handler tied
> to exact same event as the DOM0 style handler.
>
> > Is it really necessary to use old DOM0-style event handlers (the
> > attribute on the tag) and modern event attachment in the same app?
>
> Sigh.. I absolutely agree with you 100% on this. However, I do not
> have control over how this is.
> The DOM0-style comes from the server and I'm implementing a solution
> that is strictly on client side hence the ugliness of the code.
>
> >Out of curiousity, what kind of input element is it?  (That elipsis
> >could cover a lot of ground.)  button?  submit?  text?  checkbox?
>
> It is submit button.
> I appreciate any suggestion on how I might solve this problem. Thanks.
--~--~---------~--~----~------------~-------~--~----~
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