Results 1 to 3 of 3

Thread: Why doesn't this javascript code run ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    111

    Why doesn't this javascript code run ?

    I want when the user points to a picture link, the picture will become another one. But the following code will always have erros: document[...] is null or is not an object. What's the problem ?

    <script language="JavaScript" type="text/javascript">
    <!--
    productoff = new Image;
    productoff.src = "./img/product.gif";
    productover = new Image;
    productover.src = "./img/news.gif";


    function replaceImg(oldImg,newImg){
    document[oldImg].src = eval(newImg + ".src");
    }
    //-->

    </script>


    <td><a href="./product.html" onMouseOver = "replaceImg('productoff','productover')" onMouseOut = "replaceImg('productoff','productover')" ><img src = "./img/product.gif" ></a></td>

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Why doesn't this javascript code run ?

    Give the image tag a name attribute. That's what you're supposed to be passing.

    PHP Code:
    function replaceImg(imgname,newImg){
    document[imgname].src = eval(newImg ".src");

    When calling it,

    HTML Code:
    <a href="./product.html" onMouseOver="replaceImg('prodimg', 'productover');"><img src="./img/product.gif" name="prodimg"></a>

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    111

    Re: Why doesn't this javascript code run ?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width