-1

Here's the code - it's really elementary, and I can't think of what's going wrong It gives an "Object doesn't support this property or method" error in IE when the small images with the "onclick" code is clicked. It works fine in Firefox! Please help!

<script language="javascript">
    function showproduct1() 
    {
        document.getelementbyid("productimg").src = "../images/productimg1.jpg";  
    }

    function showproduct2()
    {
        document.getelementbyid("productimg").src = "../images/productimg2.jpg";  
    }    
</script>

<a href="javascript:void(0)"  title="Product 1">
    <img src="../images/productimg1.jpg" style="height: 60px" onclick="showproduct1()" />
</a><br>
<a href="javascript:void(0)"  title="Product 2">
    <img src="../images/productimg2.jpg" style="height: 60px" onclick="showproduct2()" />
</a>

<a href="../images/productimg1.jpg" target="_blank" title="Click on Image to Expand">
    <img src="../images/productimg1.jpg" width="210" border="0" alt="Product" id="productimg">
</a><br>

<br><small><strong>Click on images to expand</strong></small><p><strong>
4
  • 4
    Does this really work on Firefox ? May 23, 2013 at 19:35
  • 2
    You should study more on writing valid JS. May 23, 2013 at 19:35
  • Does this work in FiReFoX? :)
    – user1796666
    May 23, 2013 at 19:35
  • This code does not work in Fx through jsFiddle. May 23, 2013 at 19:36

2 Answers 2

7

Case matters:

document.getelementbyid

should be ...

document.getElementById

Update: I can confirm that the first example does not work in the latest version (21.0) of Fx.

2
  • I'm a little surprised this works in Firefox, in a way. I'm not sure it's a good idea to allow lazy coding that's going to break in other browsers.
    – Katana314
    May 23, 2013 at 19:53
  • @Katana314 My test of that syntax in Fx (on JSFiddle) failed. I have not tried it outside of that context though. May 23, 2013 at 19:54
1

JavaScript is case-sensitive language.

It should be getElementById not getelementbyid

Not the answer you're looking for? Browse other questions tagged or ask your own question.