Posted by: msqr | January 5, 2009

register and pass argument to event handler

Many times we are required to hook event handler with the element through javascript. Main problem we come across during this time is how to pass arguments to registered event handler.

Here’s the handy function that returns Element triggered event handler

function GetEventSource(evt)
var ie_var = "srcElement";
var moz_var = "target";

return evt[moz_var];
return evt[ie_var];

//Register event handler:
if(window.addEventListener){ // Mozilla, Netscape, Firefox
lnk.addEventListener('click', CallDoPostBackMM, false); }
else { // IE
lnk.attachEvent('onclick', CallDoPostBackMM);

function CallDoPostBackMM(evt)
var lnk= GetEventSource(evt);
//Now, you have access to lnk element:
//you can retrieve navigateURL, href, set javascript and so on.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: