locked
HTML JAVASCRIPT SLIDER NOT WORKING RRS feed

  • Question

  • User-1692850204 posted

    This is my code but it does not work.

    <script type="text/javascript">

    var image1= new image()

    image1.src = "../Images/glyndwr1redone.jpg";

    var image2 = new image()

    image2.src = "../Images/black.jpg";

    var image3= new image()

    image3.src = "../Images/glyndwrlogo1.jpg";

    //Locations of images

    </script>

    <img src="../Images/glyndwr1redone.jpg" name="Slide" alt="Image" width="848" height="300" />
    <script type="text/javascript">

    <!--
    var step=1
    function slideimage()

    {
    document.images.Slide.src = eval("image"+step+".src")

    if(step<3)

    step++

    else
    step=1
    setTimeout("slideimage()",2000)

    }


    slideimage()

    //-->
    </script>

    Any ideas as to why this does not work? 

    thanks

    Wednesday, April 24, 2013 5:59 AM

Answers

  • User-1360095595 posted

    Use document.getElementById() to get the image Covell and set the src attribute.

    Also, there no reason to create image() objects when all you want is a string for the src attribute. So you can simply declare three vars and set then to the src you want and use those in the eval().

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 24, 2013 6:21 AM