1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Javascript works in IE but not Firefox

Discussion in 'Software Development' started by tgpt, Sep 20, 2007.

Thread Status:
Not open for further replies.
  1. tgpt

    tgpt Thread Starter

    Joined:
    Jul 17, 2007
    Messages:
    5
    This code displays three images. When two of the images are moused-over, the third
    changes color. This works fine in IE but not in FireFox. I'm not very experienced in
    javascript but I did add an alert to the SetImage function and the correct images are being
    found. It seems the code in the SetImage function is not correct for FireFox. That's as far
    as I can get though. Would someone please take a look and let me know what the problem
    might be or how to troubleshoot it?
    PHP:
    <tr> 
     <td align="center" valign="middle" bgcolor="#FFFFFF"> 
     <span id="theimage"><img src="http://forums.techguy.org/images/<?php echo $product['products_image'];?>"  border=0 hspace=0 vspace=0></span> 
     </td> 
    </tr> 
    <tr> 
     <td align="center"> 
     <script> 
      var pimage=new Image(); 
      pimage.src="http://forums.techguy.org/images/<?php echo $product['products_image'];?>"; 
       
      var im1="http://forums.techguy.org/images/<?php echo $product['image1'];?>"; 
      var im2="http://forums.techguy.org/images/<?php echo $product['image2'];?>"; 
      var im3="http://forums.techguy.org/images/<?php echo $product['image3'];?>"; 
      var im4="http://forums.techguy.org/images/<?php echo $product['image4'];?>"; 
      var im5="http://forums.techguy.org/images/<?php echo $product['image5'];?>"; 
       
      var im1f=new Image(); 
      var im2f=new Image(); 
      var im3f=new Image(); 
      var im4f=new Image(); 
      var im5f=new Image(); 
       
      im1="http://forums.techguy.org/images/<?php echo $product['image1_swatch'];?>"; 
      im1f.src="http://forums.techguy.org/images/<?php echo $product['image1'];?>"; 
      im2="http://forums.techguy.org/images/<?php echo $product['image2_swatch'];?>"; 
      im2f.src="http://forums.techguy.org/images/<?php echo $product['image2'];?>"; 
      im3="http://forums.techguy.org/images/<?php echo $product['image3_swatch'];?>"; 
      im3f.src="http://forums.techguy.org/images/<?php echo $product['image3'];?>"; 
      im4="http://forums.techguy.org/images/<?php echo $product['image4_swatch'];?>"; 
      im4f.src="http://forums.techguy.org/images/<?php echo $product['image4'];?>"; 
      im5="http://forums.techguy.org/images/<?php echo $product['image5_swatch'];?>"; 
      im5f.src="http://forums.techguy.org/images/<?php echo $product['image5'];?>"; 
       
      function SetImage(newimage) 
      { 
      alert(newimage.src); 
      var imspan=document.getElementById("theimage"); 
      var html='<img id="mainimage">'; 
      theimage.innerHTML=html; 
      mainimage.src=newimage.src; 
      } 
      var im=new Image(); 
      im.src=""; 
      //SetImage(im); 
      </script> 
      <script> 
      if (im1!="http://forums.techguy.org/images/") document.write('<img src="'+im1+'" onmouseover="SetImage(im1f);" width="70">'); 
      if (im2!="http://forums.techguy.org/images/") document.write('<img src="'+im2+'" onmouseover="SetImage(im2f);" width="70">'); 
      if (im3!="http://forums.techguy.org/images/") document.write('<img src="'+im3+'" onmouseover="SetImage(im3f);" width="70">'); 
      if (im4!="http://forums.techguy.org/images/") document.write('<img src="'+im4+'" onmouseover="SetImage(im4f);" width="70">'); 
      if (im5!="http://forums.techguy.org/images/") document.write('<img src="'+im5+'" onmouseover="SetImage(im5f);" width="70">'); 
      </script> 
     </td> 
    </tr> 
     
  2. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,143
    Display the "Error Console" in Firefox when viewing your page to see what errors are being generated. I don't see the "theimage" element identified in the table row you posted above. If there is no element with the id "theimage", "document.getElementById()" won't return a valid object.

    Peace...
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/626505

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice