Link to home
Start Free TrialLog in
Avatar of ellie_07
ellie_07

asked on

simple slide show with javascript

Hi,
I'm trying to include this javascript in a web page but it isn't working and I really don't know any javascript.  I would like to be able to run a simple slide show where an image changes to the next one when the arrow button is clicked.   This is loading the first image but not showing any others when the arrow is clicked.  Thank you!!

this is the script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Experiment 4</title>
<script type="text/javascript">
//<![CDATA[

var currentPhoto = 0;
var pics = new Array();
for (var i = 0; i < 5; i++) {
  pics[i] = new Image();
}
pics[0].scr = "images/fig01-1.jpg";
pics[1].scr = "images/fig01-2.jpg";
pics[2].scr = "images/fig01-3.jpg";
pics[3].scr = "images/fig01-4.jpg";
pics[4].scr = "images/fig01-5.jpg";

function changePhoto(photo) {
      document.images[0].scr = pics[photo].src;
}

function nextPic() {
   currentPhoto++;
   if (currentPhoto < pics.length) {
           changePhoto(currentPhoto);
   } else {
     alert("at the end of the photo list");
   }
 }
 function prevPic() {
    if (currentPhoto > 0) {
        currentPhoto--;
        changePhoto(currentPhoto);
      } else {
        alert("at the beginning of the photo list");
      }
}

//]]>
</script>
<img src= "images/fig01-1.jpg" />
<p>
<a href="" onclick="nextPic();returnfalse">></a> <a href= "" onclick="prevPic(); return false"><</a>
<p>                                      
</head>

</body>

</html>


SOLUTION
Avatar of thenone
thenone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gjutras
gjutras

as well as the space mentioned
also

pics[0].scr = "images/fig01-1.jpg";
pics[1].scr = "images/fig01-2.jpg";
pics[2].scr = "images/fig01-3.jpg";
pics[3].scr = "images/fig01-4.jpg";
pics[4].scr = "images/fig01-5.jpg";

shoudl all have .src instead of .scr