William Rambow
William Rambow

Reputation: 11

TypeError: undefined is not an object

I'm having problems with the onmouseover command. I've got this little bit of code (see bottom) in my HTML code and when I try to run it on Safari 7 I get the following error:

TypeError: undefined is not an object (evaluating 'document.images.siz3.src='images/shirts/img_3siz_grey.jpg'') onmouseover

What's the problem? I can't find anything that could be wrong. The img should be defined as siz1, shouldn't it?

Maybe someone could help, I'm sure the answer's easy and I'm just not seeing it.

<a href="menu/latein/r-z/vfc/vfc.html" onmouseover="document.images.siz1.src='images/shirts/img_1siz_grey.jpg'" onmouseout="document.images.siz1.src='images/shirts/img_1_siz.jpg'" name="tshirts">
<img src="images/shirts/img_1_siz.jpg" name="siz1“  alt="Vivat floreat crescat" width="195px" height="135px"></img>

Upvotes: 0

Views: 1046

Answers (3)

Hitesh Mungpara
Hitesh Mungpara

Reputation: 36

try this code

<a href="#" onmouseover="change('change')" onmouseout="change('')">Click</a>
<img id="siz1" src="images/shirts/img_1_siz.jpg" height="200" width="200" />
<script>
    function change(str) {
        if (str == "") {
            document.getElementById('r1').src = "images/shirts/img_1_siz.jpg";
        }
        else {
            document.getElementById('r1').src = "images/shirts/img_1siz_grey.jpg";
        }
    }
</script>

Upvotes: 0

JBux
JBux

Reputation: 1394

You weren't closing the 'name' tag with the correct quotation mark.

 <a href="menu/latein/r-z/vfc/vfc.html" onmouseover="document.images.siz1.src='images/shirts/img_1siz_grey.jpg'" onmouseout="document.images.siz1.src='images/shirts/img_1_siz.jpg'" name="tshirts">
<img src="images/shirts/img_1_siz.jpg" name="siz1"  alt="Vivat floreat crescat" width="195px" height="135px"></img>

Upvotes: 0

ozil
ozil

Reputation: 7117

Looks like problem in here name="siz1“ should be name="siz1" replace to "

Upvotes: 1

Related Questions