I have the following JavaScript/HTML code:
<head runat="server">
<title>Home Page</title>
<script src="Resources/jQuery.js" type="text/javascript"></script>
<script type="text/javascript">
function change_image()
{
var url = document.getElementById('Change_Image').src;
if (url == 'http://placehold.it/200x200')
{
document.getElementById('Change_Image').src = 'http://placehold.it/100x100';
}
else
{
document.getElementById('Change_Image').src = 'http://placehold.it/200x200';
}
}
setInterval(change_image, 1000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Welcome to my Website</h1>
<h2>Below you can find an example of visual cryptography</h2>
<br />
<br />
<div><img id="Change_Image" src="http://placehold.it/200x200" alt="Letter A"/></div>
</div>
</form>
</body>
</html>
The code switches between two images every two seconds. The images are stored online.
Now, in my project, I have a folder called Resources, containing two images called Share1.bmp and Share2.bmp.
If I modify the code above to use these two images, nothing works anymore. This is how I am doing it:
if (url == '../Resources/Share1.bmp')
{
document.getElementById('Change_Image').src = '../Resources/Share2.bmp';
}
else
{
document.getElementById('Change_Image').src = '../Resources/Share1.bmp';
}
...
...
<div><img id="Change_Image" src="../Resources/Share1.bmp" alt="Letter A"/></div>
What am I doing wrong? Am I passing the url to the images stored in my project incorrectly?
EDIT
When using my images, Share1.bmp is displayed correctly, however the switching does not occur. It seems that the problem is with the URLs in the JavaScript.