P
Paulo Almeida
Hi,
I have a Javascript function called changediv() that receives as a parameter
the
number that is the id of the element I want to change:
function changediv(divnum) {
}
On the web page I have the following code:
<div id="div1" onclick="changediv(1)">...</div>
This works OK.
But if I try to use the more modern way of associating an event with
an event handler, like,
function init() {
document.getElementById('div1').onclick=changediv(1);
}
window.onload=init;
it doesn't work because of the parameter. How can I pass a parameter
in this situation?
TIA
Paulo Almeida
I have a Javascript function called changediv() that receives as a parameter
the
number that is the id of the element I want to change:
function changediv(divnum) {
}
On the web page I have the following code:
<div id="div1" onclick="changediv(1)">...</div>
This works OK.
But if I try to use the more modern way of associating an event with
an event handler, like,
function init() {
document.getElementById('div1').onclick=changediv(1);
}
window.onload=init;
it doesn't work because of the parameter. How can I pass a parameter
in this situation?
TIA
Paulo Almeida