Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: open

Message Too Old, No Replies

How to find which element fired a manually fired event?

An event fired by calling the event function through javascript

     
4:23 pm on Oct 30, 2007 (gmt 0)

5+ Year Member



I have a dynamic form which uses javascript events and such to hide and show parts of the form.

I am trying to make it so that the user can go back to the form relevant to that data and correct some of the fields but to do that I need to be able automatically show the proper parts of the form.

I can fill the fields correctly but just filling them won't fire events like onclick.

I am able to get which events to fire and fire them manully by calling, for example,

document.getElementById('someItemName').onclick();

but the problem is that I added the events to the fields with a general function checking for the srcElement and doing the appropriate things depending on which element was fired, such as,

var obj = event.srcElement;

if(obj.name == 'SomeName'){ doSomething}
else if......

And what happens when I try calling document.getElementById('someItemName').onclick(); is that it gives me an error because it cannot find event.srcElement.

Is there any solution to this one? How can I fire events manually (So the user doesn't have to click a checkbox, for example, which is already checked just to fire the onclick event).

Best Regards

NooK

4:41 pm on Oct 30, 2007 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



You might consider using the Yahoo UI Library [developer.yahoo.com]'s Event Utility [developer.yahoo.com] to create your own Custom Events [developer.yahoo.com]. This will allow you to programmatically fire your events, and has the added benefit of cross-browser functionality without you needing to worry about it.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month