I'm new to Javascripting - infact, I'm not I just having done any for ages.
I'm trying to change and image once using a function at the end of a javascript countdown. In the countdown script it says I can specify a function to call on complete.
onComplete : changeImage,
So, at the bottom of the javascript countdown timer, I wrote this:
function changeImage(a) {document.getElementById("img").src=a.src;}
</script>
The image I want to change is above the script, written here:
<a href="index.php"><img id="img" align="middle" height="450" src="images/samandwill.gif" class="logo" /></a>
I want to change the image src to "images/samandwill2.gif"
How can I do this? - I'm using Dreamweaver and PHP.
This is probably totally simple, but I'd be very grateful for some help. All I can find is answers for onclick functions, which is not what I want.
I'd really appreciate some help!
Thanks!
Will
use setTimeout
to trigger your code after a set time:
setTimeout(function(){
document.getElementById('img').src="http://placehold.it/200x200";
}, 2000);
It doesn't look like you are passing anything to the changeImage function. Also, in your change image function it looks like you are expecting an image element for a?
Here is an example:
setInterval( function(){changeImage('http://boardingarea.com/blogs/deltapoints/files/2012/07/test.jpg')},3000);
changeImage = function(a) {
current_image = document.getElementById("img");
current_image.src = a;
}
Fisrt Try it Step 1:
onComplete : changeImage(),
Step 2:
function changeImage() {document.getElementById("img").src='images/samandwill2.gif';}
</script>