function clickOnElement(srt)
{
if (srt==0)
{
elm_id = window.event.srcElement.id;
}
}
i want to call this function in onClick where srt=0. it works fine in IE but nor in firefox.
any solution???
function clickOnElement(srt)
{
if (srt==0)
{
elm_id = window.event.srcElement.id;
}
}
i want to call this function in onClick where srt=0. it works fine in IE but nor in firefox.
any solution???
It is unclear what your function does. However, I can tell you that the rough equivalent of MS's event.srcElement in FF and other modern browsers that follow standards in javascript is:
However, it's more complicated because events aren't handled the same way. In IE, you have the window.event - in all other modern browsers the event is passed automatically (intrinsically) as a part of the execution of the function and/or event - in most cases. In the other cases, the event can be passed to the function.Code:event.target
A typical example of intrinsic event passing with an IE workaround is:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function whatever(e){ var e=e? e : window.event; var event_element=e.target? e.target : e.srcElement; alert(event_element.tagName); } document.onclick=whatever; </script> </head> <body> <div>Hey!</div> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
call this functon from onclick to trigger the event by clicking on a text in a row(td) table (php)HTML Code:function clickOnElement(srt) { var elm_id = "" ; if (srt==0) { elm_id = window.event.srcElement.id; } else { elm_id = "s_" + srt; } }
PHP Code:$tree_string .= "<tr class='td-data-blank'><td idth= 40 ></td><td idth= '100%' id='s_$subroute_id' align='left' onDblClick='load_book_status()' onclick='clickOnElement(0)' class=bsmall style='color:#ffffff;cursor:pointer'>$subroute_name</td></tr>";
Your function:
doesn't do anything in any browser other than set a local variable to only the function itself. Besides, that's just not the way events get handled cross browser, and since you are activating the event from the element itself, there is no need to do it that way, even in IE.Code:function clickOnElement(srt) { var elm_id = "" ; if (srt==0) { elm_id = window.event.srcElement.id; } else { elm_id = "s_" + srt; } }
Instead of:
Use:HTML Code:onclick='clickOnElement(0)'
Then your function could work cross browser like so:HTML Code:onclick='clickOnElement(this)'
Code:function clickOnElement(srt) { var elm_id = "" ; if (typeof srt=='object') elm_id = srt.id? srt.id : null; else if (typeof srt=='string') elm_id = "s_" + srt; else elm_id = null; }
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Thanks john
Thank you jscheuer1. Your first example work good for me and is what I was looking for.
Bookmarks