PDA

View Full Version : setAttribute onmouseover multiple arg problem


roobbie
01-20-2004, 10:29 PM
curious if anyone has run into the following.

I have a web page consisting of 3 frames.
all the frames are built via perl cgi.

image names are searched for via a text input in
one frame and they are displayed in another.

I have set up the following for a on mouseover event
print "wobbie. setAttribute('onMouseOver','display_robbie($image_
id);');";
which works fine with one function argument that is a int.
If I attempt to do something like this
print "wobbie. setAttribute('onMouseOver','display_robbie($image_
id,robbie);');";

where robbie could be any var that the function display_robbie has been prototyped for the onmouseover appears to silently fails.
It also fails if I attempt to pass anything but
a number to a single arg.

so I'd be curious to know if I am doing something wrong ..or don't know something that I should ...as I would like to pass at least 3 args to this function.


thanks

rob

liorean
01-20-2004, 11:20 PM
First of all, event handlers should not be set as attributes. They should be set using either the [DOM2 Events] syntax and the iew equivalent for that browser or the classical Netscapian JavaScript syntax for cross-browser support. Second, event handlers should be lowercase, because at least iew does a direct mapping of attribute names to JavaScript properties.

So, do it this way, for browser compatibility reasons:[object DOMElement].onmouseover = function (e){
e = e || window.event;
/* This function is your event handler.
it will provide you with a this that references the
element is it appended to, and the variable e will
be your event object. From within here you can execute
any code you want, but be sure to use a syntax like
window.member instead of just member when using a
global variable or function.
*/
};