Click to See Complete Forum and Search --> : Is there a command that points to the parent elements ID?


FishyMonkey78
12-01-2003, 05:45 PM
To clarify, I want to use something like...

In the head:

homeon = new Image()
homeon.src = "homeon.gif"
homeoff = new Image()
homeoff.src = "homeoff.gif"

Obviously just to preload the images.
In the body:

function MouseOver() {
if (document.images) {
elementName.src = eval(elementName + "off.gif");
}
}

Then in the actual image I'd do

<img name="home" src="homeon.gif" onMouseOver="MouseOver()">

What I'm trying to do is to say on mouse over, check to see if images are supported, then change the source of the image the=at the function is being used in to that image's name assigned to it, plus "off.gif"

So is there a command that points to the name of the imahe the function is being used in, and will that command allow me to do what I'm trying to do?

Also, help me out with the basic script if there is a command. I know what I have right now might not work, so if there is that command, help me out on the whole function script. I'm just trying to do an entire set of mouseover's with one function.

ray326
12-01-2003, 10:17 PM
Consider using MouseOver(this).

FishyMonkey78
12-02-2003, 03:49 PM
Thank you. But now I have this code, and it doesn't seem to be working. I'm not sure why, all the relative paths are correct, and everything else makes sense.

What's wrong with this code?

<html>
<head>
<script language="javascript">
<!--
function MouseOver(element) {
if (document.images) {
elementName = element.name;
elementName.src = eval("/" + elementName + "on.gif");
}
}

function MouseOff(element) {
if (document.images) {
elementName = element.name;
elementName.src = eval("/" + elementName + "off.gif");
}
}
-->
</script>
</head>
<body>
<img name="home" src="/homeoff.gif" onMouseOver="MouseOver(this)" onMouseOut="MouseOff(this)">
</body>
</html>

All the relative paths are correct. What's

TheBearMay
12-03-2003, 08:49 AM
Try this:

function MouseOver(element) {
if (document.images) {
elementName = element.name;
element.src = elementName + "on.gif";
}
}

function MouseOff(element) {
if (document.images) {
elementName = element.name;
element.src = elementName + "off.gif";
}
}

FishyMonkey78
12-03-2003, 04:30 PM
Hey, that works, and I see why! Thanks a lot! :)