user3361624
user3361624

Reputation: 21

JavaScript is not working (slideshow)

I am using Linux and I have to write an script which slideshow some pics to the user because it takes up to 5 min for any topology (Practice labs) to load, and I have to set 2 sec wait time between each pis.I have 5 pics with this directory(/home/maziyar/slideshow/pictures/IMG01-5), they are jpg format, its not working.

<HTML>
<head>
<script type="text/JavaScript">
<!-->
var image1=new Image()
image1.src="/home/maziyar/slideshow/pictures/IMG01.jpg"
var image2=new Image()
image2.src="/home/maziyar/slideshow/pictures/IMG02.jpg"
var image3=new Image()
image3.src="/home/maziyar/slideshow/pictures/IMG03.jpg"
var image4=new Image()
image4.src="/home/maziyar/slideshow/pictures/IMG04.jpg"
var image5=new Image()
image5.src="/home/maziyar/slideshow/pictures/IMG05.jpg"
//-->
</script>
</head>
<body>
<img src="/home/maziyar/slideshow/pictures/IMG01.jpg" name="slide" width="400"         height="400"
<script type="text/JavaScript">
<!--
var step=1
function slideit(){
document.images.slide.src=eval("image"+step+".src")
if(step<5)
step++
else
step=1
setTimeout("slideit()",2500)
}
slideit()
//-->
</script>
</body>
</html>

Upvotes: 0

Views: 74

Answers (1)

Royi Namir
Royi Namir

Reputation: 148744

I will answer you , because I know that sometimes even the first step is hard. ( and obviously you did try something).

please have a look at this new code . you missed the end tag for img. and you had a code with remarks.

see it here : http://jsbin.com/wirivulu/2/edit

<head>
    <script type="text/JavaScript">
        var image1 = new Image()
         image1.src = "http://placekitten.com/110/100"
        var image2 = new Image()
         image2.src = "http://placekitten.com/120/120"
        var image3 = new Image()
         image3.src = "http://placekitten.com/130/130"
        var image4 = new Image()
         image4.src = "http://placekitten.com/140/140"
        var image5 = new Image()
         image5.src = "http://placekitten.com/150/150"
         //-->
    </script>
</head>

<body>
    <img src="http://placekitten.com/100/100" name="slide" width="400" height="400" />
    <script type="text/javaScript">
        var step = 1

            function slideit()
            {
                document.images.slide.src = eval("image" + step + ".src")
                if (step < 5)
                    step++
                else
                    step = 1
                setTimeout("slideit()", 2500)
            }
        slideit()
    </script>
</body>

</html>

Upvotes: 1

Related Questions