You're really basically there, except you're event handler is a bit
redundant.

function submitFunction(ev) {
    ev.stop();
    console.log(this)
}

$("f1").addEvent("submit", function(ev) {
    submitFunction.attempt(ev, $("f1"))
});

Why are you wrapping the submitFunction inside an anonymous function?

By definition, the "this" inside that function will the the element it
fires on.

Just do:

$('f1').addEvent('submit', submitFunction);

and call it a day ;)


On May 9, 8:35 am, "Steve Onnis" <[email protected]> wrote:
> I am wondering which is the best way to use a common function for element
> events.
>
> For example, i have a form that loads on the page, then on that same page i
> have an ajax window that opens that has other forms and i want to assign the
> same submit event function for both forms. Because i need to add the events
> to the forms in the ajax window programmatically i want to create a generic
> function which i can assign to multiple forms.
>
> Is this the best way to do it?
>
> http://jsfiddle.net/LWUX3/
>
> Steve

Reply via email to