views:

201

answers:

3

i have some javascript roll over code that works fine in firefox but when i try it in IE i get this error:

Message: 'document[...]' is null or not an object Line: 25 Char: 13 Code: 0 URI: http://www.jgm-design.com/

the code im using is:

if (document.images)
{
    image1 = new Image;
    image2 = new Image;
    image1.src = "images/logos/logoBlackFadedLow.jpg";
    image2.src = "images/logos/logoWhiteFadedLow.jpg";
}

function chgImg(name, image)
{
    if (document.images)
    {
        document[name].src = eval(image+".src");
    }
}

Any idea why? Or a solution?

A: 

try document.getElementsByName(name) instead of document[name]

Sergio
+1  A: 

Aren't you lacking a ".name" => document.images[name].src = ...

streetpc
+1  A: 

The error indicates that the image you're trying to change by name doesn't exist. Unless you post exactly how you're calling the method (chgImg) and what your HTML is, however, I can't really help you specifically.

PS: This is some quite outdated code. It would be a good idea to consider using css :hover pseudo-classes for this problem, as well as finding some more recent javascript to work with.

Rahul
good call, changed to css method and it works now thanks :D