Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

swapping images, easy? 1

Status
Not open for further replies.

Mariootje

Programmer
Aug 10, 2001
33
NL
Hello there,

I'm trying to make an very easy imageswap (that is what I thought at least), just by clicking on an image the next image has to appear, by clicking again the previous should appear. The code I have so far looks like this (thanks Banger):

<html>
<head>
<title>test</title>
<script language=&quot;javascript&quot;>
var changeMeBackPlease = false;

function imageSwap(image){
// change image back
if(changeMeBackPlease==&quot;false&quot;){

image.src = OLDSRC;
}
else
{

image.src = &quot;images/plusje.gif&quot;; HERE I GET AN (DEBUG)ERROR: &quot;UNDEFINED IS 'NULL' OR NOT AN OBJECT&quot;
}

// reset the variable depending what it is now
// Just swaps or inverts the true/false value

changeMeBackPlease =(changeMeBackPlease)?false:true;
}
</script>
</head>
<body>
<img src=&quot;images/woordassistentie.gif&quot; OLDSRC=&quot;images/woordassistentie.gif&quot; onClick=&quot;imageSwap()&quot;>
</body>
</html>

So, I get the image woordassistentie.gif, but when clicking it I get an error and do not get plusje.gif.

Any suggestions?

Thanks, Mariootje
 
Mariootje

This is because you have defined imageSwap as:

Code:
function imageSwap( image )

But are calling the function with no arguments:

Code:
onClick=&quot;imageSwap()&quot;

Hence the 'image' object will be null.

Try calling the function as:

Code:
onClick=&quot;imageSwap( this )&quot;

Groetjes uit Engeland, Neil :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top