On 27 May, 11:33, szimek <szi
...@gmail.com> wrote:
> Hi,
> I made a behavior for span elements that simply toggle themselfes
> between add/cancel state and additionally toggle some element on the
> page (i.e. a form) on onclick event -http://gist.github.com/118542.
> It works fine, but the problem is when this is used to show i.e. a
> form. In this case I'd like onclick event handler to be executed when
> the form is submitted, so that I can hide the form and update span
> element. The main problem is that I can't simply fire onclick event on
> span element, which would solve the problem.
> Do you have any other ideas how to solve it?
Assuming the form and the span tags are closely related, why not just
create the behavior on a containing element?
Then you can have an internal function in the behavior, that can be
called from both onclick and onsubmit events.
If you use event delegation with Low Pro, it's actually quite simple.
I recently gave a very brief intro to Low Pro at a local JavaScript
meetup, and for that purpose I created a small behavior for a form,
that has both an onsubmit event listener as well as an event delegate.
You can check out the details http://roderick.dk/blog/2009/05/07/introduction-to-low-pro-for-protot...
and from studying the example a bit, I am pretty sure it becomes clear
how to create behaviors that use containing elements.
/Morgan