Simple Image Swap

Hi,
I’m new to Javascript and just trying to create a simple in-line image swap. Here is my code:


<SCRIPT LANGUAGE=JavaScript>
function swapImage() {
var image = document.getElementById("wordsearch")
image.src = "images/fall2011-wordsearchans.gif"
}
</SCRIPT>

<img id="wordsearch" src="images/fall2011-wordsearch.gif" onclick="swapImage();" border="0" />

You can view the implementation here:
http://www.klingstedtbrothers.com/word-search

The page displays but the image does not swap. Any ideas? I’m sure it’s something simple.

Okay I got it working using totally different code. This code also allows the image to switch back to the original with a second click.


<script language="JavaScript" type="text/JavaScript">
var q=0;
function swapImage(){
if(q==0){
document.getElementById("wordsearch").setAttribute('src','images/fall2011-wordsearchans.gif');
q++;
}
else{
document.getElementById("wordsearch").setAttribute('src','images/fall2011-wordsearch.gif');
q--;
}
}
</script>

<img id="wordsearch" src="images/fall2011-wordsearch.gif" onclick="swapImage();" border="0" />

Hello KlingstedtBros - just wanted to thank you for posting the thread above - REALLY nice and simple (like the title says) function. Thank you for sharing your knowledge.