Dear omoolorun,
The reason your page correctly displays the first picture is that its
location is specified by the HTML code as src="d:\1.jpg", which
translates directly into the string "d:\1.jpg".
But when you click on the "Next Picture" link and the JavaScript gets
called, the next element of the array is "d:\2.jpg", which gets
translated by the JavaScript interpreter into the invalid location
"d:%02.jpg". This is because the backslash character, "\", has a
special meaning in JavaScript that causes it to render special
characters. If you intend a JavaScript string to include the backslash
character itself, you must write it twice in a row: "\\". Thus, when
you are using a JavaScript string to specify the file location
d:\2.jpg, you should write it as "d:\\2.jpg".
You will find that the HTML source code below achieves the intended
effect. If you wish to preserve your own prefatory tags, you can just
cut the script out of your current file and paste in my own as a
substitute.
If you have any trouble carrying out this substitution, please advise
me through a Clarification Request so that I can make sure everything
is working at your end before you rate my answer.
Regards,
leapinglizard
<html>
<head>
<script language="JavaScript">
//<!--
var picture = new Array("d:\\1.jpg", "d:\\2.jpg", "d:\\3.jpg",
"d:\\4.jpg", "d:\\5.jpg", "d:\\6.jpg",
"d:\\7.jpg", "d:\\8.jpg");
var picNumber = 1;
var numberofPics = picture.length;
function nextPicture() {
if (picNumber < numberofPics){
picNumber++;
}
else {
picNumber = 1;
}
//alert(picture[picNumber-1]);
document.myPicture.src = picture[picNumber-1];
}
//-->
</script>
</head>
<body>
<center>
<img src="d:\1.jpg" name="myPicture" width=400, height=400>
<p>
<a href="JavaScript:nextPicture()">Next Picture</a>
</p>
</center>
</body>
</html> |