Forum Moderators: open
The issue is whenever I add any parameters to the function I want to execute on the event all browsers (IE, Gecko, Opera, Webkit) then decide to execute it during the onload event! The addEventListener events must be called during onload correct? So why the heck does the act of adding parameters automatically make the event listeners trigger during the onload event? This completely negates the point of having the event listeners! :(
The following script is loaded via the onload event...
if (!document.all) {document.getElementById('menua5k').addEventListener('click', test_menus, false);}
else {document.getElementById('menua5k').attachEvent('onclick', test_menus);}
Here is the exact same code (each) with a simple parameter...
if (!document.all) {document.getElementById('menua5k').addEventListener('click', test_menus('hi there!'), false);}
else {document.getElementById('menua5k').attachEvent('onclick', test_menus('hi there!'));}
- John
- John
function test_menus(example)
{
alert(example);
}function start_onload
{
if (window.addEventListener)
{
var object = document.getElementById('menua5k');
object.addEventListener('click',function() {test_menus('hello');},false);
object.myflag = 'test success!';
}
else
{
var object = document.getElementById('menua5k');
object.attachEvent('onclick',function() {test_menus('hello');});
object.myflag = 'test success!';
}
}