Possible Duplicate:
How to pass arguments to addEventListener listener function?
How can I pass some argument (in this case an integer) to a function through addEventListener
on a click
event?
I have two buttons; if I press the right one I want to do some stuff, if I press the left one then I'd like it to do something else.
Here's the code:
document.getElementById('date_right').addEventListener( 'click', switch_date(1), false );
document.getElementById('date_left').addEventListener( 'click', switch_date(-1), false );
function switch_date( k )
{
if(k==1)
{
//do stuff
}
else
{
//another stuff
}
}