I am currently working on using Javascript arrays to swap images for rollover buttons.
This was working perfectly for one build about a week ago. That is, I am working on something else now and tried to use the same code that worked for this - it's broken now;
-A difference is that I am building this new dev locally. It is not on a live server yet. That really should not matter-- right?
-A broken image icon is displayed. There seems to be a roll-over effect occuring, though. This indicates to me that the path to the image is not linked correctly, something rather simple yet I can't seem to fix it.
I find some of the OO aspects a bit confusing: It seems that an image is turned into an object simply to be able to process it from within an array, programatically. But, HTML is needed to call the actual image for display. I guess I am confused as to why an image must be turned into an object. This I need to understand.
But, I am trying understand this fully, not just hack away at code/mark-up.
Thank you in advance for any points in the right direction(s).
`Inline Code Example Here
<head>
<!--js button swap code part 1-->
<script type="text/javascript">
<!--
if(document.images)
{
var image_array = new Array();
// path to the directory with images
var path = '/images/';
// enumeration of the "active" images
image_array[0] = path + "images/black_menu2.jpg";
image_array[1] = path + "images/black_history2.jpg";
image_array[2] = path + "images/black_contact2.jpg";
var preload_image = new Array ();
for(var i=0; i<image_array.length; i++)
{
preload_image[i]= new Image();
preload_image[i].src = image_array[i];
}
}
//-->
</script>
</head>
<body>
<!--js button swap code part 2-->
<script type="text/javascript">
<!--
function rollover(name, filename)
{
var fullpath = '/images/' + filename;
document.images[name].src = fullpath;
}
//-->
</script>
<!--html button swap -->
<a href="#" onmouseover="rollover('button1','black_menu2.jpg')" onmouseout="rollover('button1','black_menu1.jpg')"><img src="/images/black_menu1.jpg" name="button1"
width="185" height="30" border="0"></a>
</body>
`
-Matthew