View Full Version : [FIXED]Global Variable Issue? Or just internet explorer?

04-29-2008, 08:00 PM
Basically. I have a row of images, this is probably a bad way of doing it, but I thought it was quite sufficient. I want to highlight an image when clicking it, and dehighlight any others that are highlighted so only one is at a time. Here is the code:

Here's the image example:

<img src="image1.png" onclick="setTargetImage(this)" alt="Image"/>
<img src="image2.png" onclick="setTargetImage(this)" alt="Image"/>
<img src="image3.png" onclick="setTargetImage(this)" alt="Image"/>
<img src="image4.png" onclick="setTargetImage(this)" alt="Image"/>
<img src="image5.png" onclick="setTargetImage(this)" alt="Image"/>

var currentImage = '';
var newImage;

function setTargetImage(theImage) {
if (currentImage != '') {
currentImage.style.backgroundColor = '';
theImage.style.backgroundColor = 'red';
currentImage = theImage;

In firefox, it works fine. What I expect it to do is store the current image in a variable, then when the function is next called, it'll turn off the old image and highlight a new. In firefox it seems fine, internet explorer is expecting an object. What is the internet explorer version because obviously theImage.style.backgroundColor isn't working as a correct object. Is it just I'm not passing it correctly in the image onclick part? Or does internet explorer have different syntax for objects that I'm unaware. It must be painfully obvious because normally this isn't an issue for me. But I'm missing something =/ Help would be appreciated.

Sorry for the n00b question.

Just had to clear private data. Odd error.