0

How do i change images every 5 seconds on my web page? I have tried something but the first image is getting displayed but the rest of the images r not and i have used update panel and timer

3
Contributors
7
Replies
30
Views
2 Years
Discussion Span
Last Post by fastina hasini
0

Use JavaScipt. In the HEAD section in your HTML:

<script src="js/nameofjavascript.js" type="text/javascript"></script>

In the BODY section, place an IMG element with the name tag set to for example "slide", likte this:

<img src="picture1.png" name="slide" width="800" height="200" />

Example JavaScript:

    var image1 = new Image()
    image1.src = "picture1.png"

    var image2 = new Image()
    image2.src = "picture2.png"

    var image3 = new Image()
    image3.src = "picture3.png"
    var step = 1
    function slideit() {
        document.images["slide"].src = eval("picture" + step + ".src")
        if (step < 3)
            step++
        else
            step = 1
        setTimeout("slideit()", 5000)
    }
    slideit()

Edited by Sugmuffen

0

I dont understand... where should i type the fuction and those declaration lines??? :(

0

You mentioned that you have used update panel and timer but the javascript that was recommneded by Sugmuffen may be less complicated than trying to use asp.net controls.

Are you familiar/experienced with Javascript?

0

You can put the .js file and .html file in the same directory if you want. In my example I used

<script src="js/nameofjavascript.js" type="text/javascript"></script>

This means that the nameofjavascript.js file resides in a sub-directory called js. If you instead use

<script src="nameofjavascript.js" type="text/javascript"></script>

then the javascript file nameofjavascript has to be placed in the same directory as your .html file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.