2

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?

Georg Schölly
  • 124,188
  • 49
  • 220
  • 267

3 Answers3

1

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

instanceof me
  • 38,520
  • 3
  • 31
  • 40
1

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
  • 12,181
  • 5
  • 43
  • 64
0

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

Sergio
  • 8,125
  • 10
  • 46
  • 77