Hello I would like to ask your help regarding javascript code, how do I have this work?
I have saved the images in my D drive. Do I need to change some path here:
Thanks
<html>
<head>
<script type="text/javascript">
<!--
var image1=new Image()
image1.src="pic001.png"
var image2=new Image()
image2.src="pic002.png"
var image3=new Image()
image3.src="pic003.png"
//-->
</script>
</head>
<body onLoad="slidit()">
<img src="pic001.png" name="slide" width="400" height="120" />
<script>
<!--
//variable that will increment through the images
var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("images"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 1 seconds
setTimeout("slideit()",1000)
}
slideit()
//-->
</script>
</body>
</html>
Why give static/absolute path? Use relative path in your webapp. And if you are just practicing with single HTML then just put all the images in same folder in which HTML resides.
Relative Path
It means the file path to where the image is located “relative” to the HTML page. In other words you determine the path to the image with the HTML page as the starting point. For example:-
Absolute Path
Absolute paths are a different than Relative paths in that it doesn’t matter where the image files are located relative to your web pages. This is because you tell the browser exactly where the file is on the web.Example:-
See this for more help.
In your code following is the code where you use image path:
Update:-
Because your html and images are in same folder you should write like this:
My demo working code:
Above is my demo code which is working fine. I have made some changes in your code it will now change image on interval. I hope this is what you want. You have to change image path as you used in your code other things are okay and ready to go.