Friday, 21 December 2012

Photo Album example using arrays in javascript

<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> var iarray=new Array("Desert.jpg","Hydrangeas.jpg","Jellyfish.jpg", "Lighthouse.jpg","Sunset.jpg","Winter.jpg"); var current=0; function next() { if(current == (iarray.length -1)) current=0; else current++; document.getElementById("photo").src=iarray[current]; } function previous() { if(current == 0) current=iarray.length -1; else current--; document.getElementById("photo").src=iarray[current]; } </SCRIPT> </HEAD> <BODY> <center> <img height="300" id="photo" src="Desert.jpg" width="300"/></br></br> <hr> <INPUT TYPE="button" VALUE="Previous" ONCLICK="previous();"> <INPUT TYPE="button" VALUE="Next" ONCLICK="next();"> </center> </BODY> </HTML>

No comments:

Post a Comment