# Javascript: Images go blank, what's wrong?

**URL:** https://boards.straightdope.com/t/javascript-images-go-blank-whats-wrong/226018
**Category:** Factual Questions
**Created:** [January 25, 2004, 5:56pm UTC](https://boards.straightdope.com/t/javascript-images-go-blank-whats-wrong/226018 "2004-01-25T17:56:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)
#### Post date: [January 25, 2004, 5:56pm UTC](https://boards.straightdope.com/t/javascript-images-go-blank-whats-wrong/226018/1 "2004-01-25T17:56:19Z")

</div>

I’m trying to get this ‘onMouseOver’ script to work, but when ever I move the mouse over the image, it just goes blank with a rectangle around it. I’m not getting any script errors, and nothing really stands out as being wrong. Here’s the code I’m using:  
\<script\>  
if (document.images) {

// on images  
image1on = new Image();  
image1on.src = “menu\_djs\_on.gif”;

// off images  
image1off = new Image();  
image1off.src = “menu\_djs\_off.gif”;

}

function changeImages() {  
if (document.images) {  
for (var i=0; i\<changeImages.arguments.length; i+=2) {  
document[changeImages.arguments\*].src = eval(changeImages.arguments[i+1] + “.src”);  
}  
}  
}  
\</script\>

There are about 8 image statements, but I’ll just show you just enough code for 1, to shorten up this post.  
This is the image html coding:

\<td height=“13” width=“36”\>  
**\<a onmouseout=“changeImages(‘image1’, ‘image1off’)” onmouseover=“changeImages(‘image1’, ‘image1on’)” href=“[http://www.yahoo.com](http://www.yahoo.com)”\>**  
\<img border=“0” height=“13” width=“36” src=“menu\_data/menu\_djs\_off.gif” name=“image1”\>\</a\>\</td\>  
It is just a simple link, that when you put the mouse over the image, it changes color, nothing real fancy. See anything wrong here?

---

<div class="post-metadata">

### Author: ![Hauky](https://avatars.discourse-cdn.com/v4/letter/h/0ea827/32.png) [@Hauky](https://boards.straightdope.com/u/Hauky)
#### Post date: [January 25, 2004, 6:37pm UTC](https://boards.straightdope.com/t/javascript-images-go-blank-whats-wrong/226018/2 "2004-01-25T18:37:24Z")

</div>

You have to include the subdirectories in the .src at the top. Since the actual image has a src of “menu\_data/menu\_djs\_off.gif”, your code should look more like:

image1on = new Image();  
image1on.src = “menu\_data/menu\_djs\_on.gif”;

image1off = new Image();  
image1off.src = “menu\_data/menu\_djs\_off.gif”;

As it is now, it’s simply not finding the images.

---

<div class="post-metadata">

### Author: ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)
#### Post date: [January 25, 2004, 6:45pm UTC](https://boards.straightdope.com/t/javascript-images-go-blank-whats-wrong/226018/3 "2004-01-25T18:45:21Z")

</div>

:smack: Thanks **Hauky** , worked like a charm!  
Time for coffee.
