Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onmouseover/ommouseout not working for me! 1

Status
Not open for further replies.
Feb 16, 2003
87
GB
Hello!

I'm using the code from:


which seemed quite good. I have about 11 images I want to be able to swap and I'm using this code:

<script type=&quot;text/javascript&quot;>
var revert = new Array();
var inames = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11');

// Preload
if (document.images) {
var flipped = new Array();
for(i=0; i<inames.length; i++) {
flipped = new Image();
flipped.src = &quot;images/&quot;+inames+&quot;b.gif&quot;;
}
}

function over(num) {
if(document.images) {
revert[num] = document.images[inames[num]].src;
document.images[inames[num]].src = flipped[num].src;
}
}
function out(num) {
if(document.images) document.images[inames[num]].src = revert[num];
}
</script>


and this in the img src:

<img border=&quot;0&quot; src=&quot;images/1.gif&quot; name=&quot;1&quot; onMouseOver=&quot;over(0)&quot; onMouseOut=&quot;out(0)&quot; width=&quot;379&quot; height=&quot;24&quot;>

Only when I run the page it swaps the wrong images? It seems to be getting confused with images that I don't want swapping (like the logo at the top of the page!!)

Any ideas what might be wrong with the script?

Thanks in advance.

Simon
 
My guess is, the use of numbers in the array
instead of names, is confusing the browser;

images have an index as well as a name.

Try renaming a couple of images with alpha
names like so:
(as in the source url you gave above)

var inames = new Array('one', 'two', 'three'

and rename your images:
1 > one
2 > two
3 > three

2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top