Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts

    [FIXED]Global Variable Issue? Or just internet explorer?

    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:

    Code:
    <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"/>
    Code:
    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.
    Last edited by flynch01; 04-29-2008 at 09:06 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •