Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Target ID returns nothing in Firefox - Works in Google Chrome 1

Status
Not open for further replies.

walkingseed

Technical User
Jan 1, 2006
12
0
0
US
I am having trouble catching events in Firefox. the below code works in Chrome but does not work in Firefox. How do I get the event target id in Firefox. I have been fighting this for far too long for as easy a problem as it should be and its got me frustrated.

// Attached listeners to the web page
function attach_events_obj() {
document.addEventListener('click',
function(){
do_click();
}, false);
}


// Process the click event
function do_click() {

// Determine if browser is IE or FF and get the event source element ID
var e_click = e_click || window.event;
var target = e_click.target || window.event.srcElement;
var obj_id = target.getAttribute('id');

// take action for the element that was clicked
if(obj_id == "people") {
document.frm_people.submit();
} else if(obj_id == "vendors") {
document.frm_vendors.submit();
}
}

// START HERE
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", attach_events_obj, false);
}
 
Hi

There is no reason for that to work in any standard compliant browser.
[ul]
[li]when setting up the event handling [highlight]pass a reference[/highlight] to the event handler function[/li]
[li]declare an e_click [highlight pink]formal parameter[/highlight] to your event handler function[/li]
[/ul]
Without these two things the function will receive no information about the circumstances.
Code:
[b]function[/b] [COLOR=darkgoldenrod]attach_events_obj[/color][teal]()[/teal]    [teal]{[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]addEventListener[/color][teal]([/teal][green][i]'click'[/i][/green][teal],[/teal] [highlight]do_click[/highlight][teal],[/teal] [b]false[/b][teal]);[/teal]
[teal]}[/teal]

[b]function[/b] [COLOR=darkgoldenrod]do_click[/color][teal]([/teal][highlight pink]e_click[/highlight][teal])[/teal]    [teal]{[/teal]
[gray]// ...[/gray]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top