quick js issue:

Soldato
Joined
19 Oct 2002
Posts
3,480
hi peeps

a mate just asked me to look at this code, i know the solution is probably very easy but i'm not particularly good with javascript so i though i'd post it here as one of you is bound to be able to eat it right up :)

its a simple exercise to create a manual (next/previous) slideshow...

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type"
          content="text/html; charset=ISO-8859-1"/>
    <title>Ex6 Slideshow</title>
    <script type="text/javascript">
    var pic=new Array();
    pic[0]=new Image(); pic[0].src='imgs/R1.jpg'
    pic[1]=new Image(); pic[1].src='imgs/R2.jpg'
    pic[2]=new Image(); pic[2].src='imgs/R3.jpg'
    pic[3]=new Image(); pic[3].src='imgs/R4.jpg'
    pic[4]=new Image(); pic[4].src='imgs/R5.jpg'
    pic[5]=new Image(); pic[5].src='imgs/R6.jpg'
    pic[6]=new Image(); pic[6].src='imgs/R7.jpg'
    pic[7]=new Image(); pic[7].src='imgs/R8.jpg'
    pic[8]=new Image(); pic[8].src='imgs/R9.jpg'
    pic[9]=new Image(); pic[9].src='imgs/R10.jpg'
    var i=0; // current image

    function step(imgID)
    { i++
      if(i>9) { i=0 }
      document.getElementById(imgID).src = pic[i].src
    }
    </script>
  </head>
  <body>
    <h1>Ex6 Slideshow</h1>

    <p><img id="i01" src="imgs/R1.jpg" alt="image slideshow"
            height="612" width="459" /> <br/>
       <input type="button" value="Next" onclick="step("i01")"/>
       <input type="button" value="Previous" onclick="" />
    </p>
  </body>
</html>

i'm good enough to know it hasn't god a chance of working in its current form :p...

cheers :)
 
Code:
onclick="step("i01")"
should be:
Code:
onclick="step('i01')"
(note the single quotes).

What exactly are you asking for help with?
 
like i said it isnt my code, but my knowledge of js isnt good enough to get this working cuz at present when you press the buttons, nothing happens...
 
Looks like when clicking on the button, it adds 1 to a counter (i) that determines what picture to show.

I don't know Javascript but it doesn't appear as though it is refreshing the page?

I coud be wrong tho.
 
Last edited:
Back
Top Bottom