Forum Moderators: open

Message Too Old, No Replies

Event accessing problem

         

Mohsen

2:35 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



Hi,
I'm trying to fire a registered event manually. I'm using obj.addEventListener on Mozilla and obj.attachEvent on IE . Is there any method to fire events registered on an element?

The classic event registeration mechanism works fine, since we can just write:


formObj.onsubmit = anEvent;

and call it easily with
formObj.anEvent();

DrDoc

3:53 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have two options:

1) fire the event which would trigger the function call
2) call the function directly

So, in your example:

formObj.onsubmit = anEvent;

1)

formObj.submit();

2)
anEvent();

Both would cause the specified function to be run. The difference is just whether you actually want the form submission (or link click, or whatever else events you are capturing) to actually take place or not.

Mohsen

11:51 am on Apr 9, 2006 (gmt 0)

10+ Year Member



1) fire the event which would trigger the function call

It doesn't work! You know that events are not fired when the corresponding javascript method is called. For example form.submit() will not fire onsubmit event.

DrDoc

6:30 pm on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should fire the corresponding event.

<a href="#" onclick="alert('I was clicked'); return false;" id="somelink">Click me</a>
<a href="javascript:document.getElementById('somelink').click()">Click the above one.</a>