Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
It does looks wrong to me...
What you should give here, is just the name of the function to be used. When that function is called, it's like an "eval".
The event can fire synchronously, but it could by asynchronous too. In the last case, the value of myVariable can be different than the one in your page.
You have to handle that into the function itself.
And remember that a function in javascript can receive an parameter, even if it's not declared.
In the case of an event, you will receive a "this" variable in your function that will be related to the element that have triggered the event.
http://developer.mozilla.org/en/docs...in_the_handler
So, the proper way (if I want to be extrem) would even be:
http://developer.mozilla.org/en/docs...dEventListener
Code:
try{
//for anything except IE
image.addEventListener('mouseover',myFunction,false);
}
catch e{
//for IE
image.attachEvent('onmouseover',myFunction);
}
function myFunction(){
var myVariable=this.some_property.value;
alert myVariable;
}
or:
Code:
image.onmouseover=myFunction;
function myFunction(){
var myVariable=this.some_property.value;
alert myVariable;
}
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 07-31-2008 at 05:56 PM..
|