I am trying to set an image dynamically at runtime using javascript. However i always get 404 error in firebug saying image could not be found. when i run this the javascript seems to look for the image in the Home Folder rather than the image folder. Am i missing a format to specify the image urls?
Why is it looking at that location whereas it should be looking at Images folder in the solution?
Also if i make that javascript external the html cannot access it even though my references to the js file are correct.
Anyone willing to contribute on this? you help be very much appreciated.
Here is my code
Html
<body onload="startTime();">
<div class="img">
<img id="img1" border="0" src="~/Images/Ghandrukpic4.jpg" alt="GhanddrukPic4" class="image" />
</div>
</body>
Javascript Code
$(function () {
function startTime() {
var imgArray = new Array("Images/60987Ghandruk Village.jpg", "Images/GhandrukPic2.jpg", "Images/ghandrukpic3.jpg");
var imgCount = 0;
if (imgCount == imgArray.length) {
imgCount = 0;
}
document.getElementById("img1").src = imgArray[imgCount];
imgCount++;
setTimeout("startTime()", 5000);
}
});