Results 1 to 6 of 6

Thread: srcElement problem in firefox

  1. #1
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question srcElement problem in firefox

    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???

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    event.target
    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.

    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

  3. #3
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    HTML Code:
    function clickOnElement(srt)
    {
    	var elm_id = "" ;
    	if (srt==0)
    	{ elm_id = window.event.srcElement.id;	}
    	else
    	{ elm_id = "s_" + srt; }
    }
    call this functon from onclick to trigger the event by clicking on a text in a row(td) table (php)
    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>"

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Your function:

    Code:
    function clickOnElement(srt)
    {
    	var elm_id = "" ;
    	if (srt==0)
    	{ elm_id = window.event.srcElement.id;	}
    	else
    	{ elm_id = "s_" + srt; }
    }
    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.

    Instead of:

    HTML Code:
    onclick='clickOnElement(0)'
    Use:

    HTML Code:
    onclick='clickOnElement(this)'
    Then your function could work cross browser like so:

    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

  5. #5
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks john

  6. #6
    Join Date
    Nov 2010
    Location
    Lima, Perú
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you jscheuer1. Your first example work good for me and is what I was looking for.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •