<html>
<head>
<title>swapimage</title>
</head>
<script>
var arr=["C:\Documents and Settings\Mohan Krishna\Desktop\ku20.gif","C:\Documents and Settings\Mohan Krishna\Desktop\b30.gif","C:\Documents and Settings\Mohan Krishna\Desktop\goku12.gif"];
i=0;
function swap()
{
document.images[0].src=arr[i];
i++;
if(i==3)
i=0;
setTimeOut("swap()",5000);
}
</script>
<body bgcolor="white">
<marquee behaviour="alternate" direction="left"><img src="C:\Documents and Settings\Mohan Krishna\Desktop\UNUSED DESKTOP ITEMS\batman5.gif" onClick=swap()>
</marquee>
</body>
</html>

Think I made just one adjustment and it works now.

<html>
<head>
<title>swapimage</title>
</head>
<script>
var arr=["img/wysiwyg_buttons/bold.gif","img/wysiwyg_buttons/italic.gif","img/wysiwyg_buttons/strike.gif"];
i=0;
function swap()
{
document.images[0].src=arr[i];
i++;
if(i==3)
i=0;
setTimeOut("swap()",5000);
}
</script>
<body bgcolor="white">

<marquee behaviour="alternate" direction="left" onClick="swap();"><img src="img/wysiwyg_buttons/link.gif" >
</marquee>
</marquee>
</body>
</html>

After I moved the onclick event, it worked fine.

> unable to swap images using arrays in javascript

Not surprising considering that the marquee tag is non-standard, deprecated and has no onclick attribute.

Try this:

<html>
<head>
<title>swapimage</title>
</head>
<script>
var arr=["C:\\Documents and Settings\\Mohan Krishna\\Desktop\\ku20.gif","C:\\Documents and Settings\\Mohan Krishna\\Desktop\\b30.gif","C:\\Documents and Settings\\Mohan Krishna\\Desktop\\goku12.gif"];
i=0;
function swap()
{
document.images[0].src=arr[i];
i++;
if(i==3)
i=0;
setTimeOut("swap()",5000);
}

swap();
</script>
<body bgcolor="white">
<marquee behaviour="alternate" direction="left"><img src="C:\\Documents and Settings\\Mohan Krishna\\Desktop\\UNUSED DESKTOP ITEMS\\batman5.gif" onClick=swap()>
</marquee>
</body>
</html>

This is JavaScript, remenber?
p.s.: you don't need "onclick" event since your swaper has a timer.
Regards.

Thank you for your effort i had tried in both the ways as suggested but still have the same problem one thing i forgot to tell you images are not appearing when i click on the image.I think this would help you in some extent.

I tested it and it works fine for me, so I'm thinking it may be an image formatting problem on top of the javascript error.

no it is working fine now i just replaced the image from desktop to my documents.

no it is working fine now i just replaced the image from desktop to my documents.

Hmm. I wonder what the difference is?
:-/

no it is working fine now i just replaced the image from desktop to my documents.

Hmm. I wonder what the difference is?
:-/

The difference is in that he was actually asking his browser to load images located on his "desktop" from "my documents" folder!

And guess what?
( This is funny :D )

... one thing i forgot to tell you images are not appearing...

They weren't there!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.