Michael Bar-David wrote:

JS question:

I'm trying to work with addEventListener, to implement this code:

<input type='button' id='bt1' value='press me' onclick='foo(1)'/>

with JS:

document.getElementById('bt1').addEventListener('click',***);

what sould I write instaed of *** ?

(The problem is, how to pass the parameter to to function)

It depends on how you want to distinguish between buttons. For instance, if the parameter is always the third letter of the id you can write an intermediate function:

function onInputClicked(event) {
   foo(event.target.id[2]);
}

Alternatively you could use the button's name, or a custom attribute. Otherwise you would have to write a separate function for each button.
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners

Reply via email to