I am trying to display pictures on a simple website
and want a next button
Rather than have an html file for each picture and have to maintain all the links, I want to use an array and update the image when the user clicks on the next button
I will have more than one of these galleries so want to store the function to find the next image in the list in a js file but have the array defined in the html file.
When I define it as below it doesnt work, but when I move the array declaraction and NextPic() function into the js file it does.
Can anyone tell me what I'm doing wrong.
test.html
test2.js
Thanks in advance
Snuv
"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary
and want a next button
Rather than have an html file for each picture and have to maintain all the links, I want to use an array and update the image when the user clicks on the next button
I will have more than one of these galleries so want to store the function to find the next image in the list in a js file but have the array defined in the html file.
When I define it as below it doesnt work, but when I move the array declaraction and NextPic() function into the js file it does.
Can anyone tell me what I'm doing wrong.
test.html
Code:
<SCRIPT LANGUAGE="JavaScript" src="test2.js">
var PictureArray=new Array();
PictureArray[0]="1808.jpg";
PictureArray[1]="1815.jpg";
PictureArray[2]="1766.jpg";
PictureArray[3]="1767.jpg";
PictureArray[4]="1789.jpg";
currentPicture="1808.jpg";
function NextPic()
{
currentPicture=NextPicture(PictureArray,currentPicture);
alert(currentPicture);
}
</SCRIPT>
test2.js
Code:
function NextPicture(lst,CurrentPic)
{
limit = lst.length;
RetVal = "";
for (i=0;i<limit;i++)
{
pic = lst[i];
if (pic==CurrentPic)
{
if (i==limit-1)
{
RetVal = lst[0];
}
else
{
RetVal = lst[i+1];
}
i=limit;
}
}
return RetVal;
}
Thanks in advance
Snuv
"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary