Why doesn't onmouseover work in a function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • OM

    Why doesn't onmouseover work in a function?

    Why doesn't a onmouseover function work in a function?
    (It's prob due to my code being wrong more than anything else!)

    I've got the following code (snippet):

    <!-- Begin
    var image0 = new Image(); image0.src = "blank.jpg" ;
    var image1 = new Image(); image1.src = "map.jpg";
    // End -->

    function swapTheImages()
    {
    image0.src='1.j pg'; image1.src='2.j pg'; image2.src='2.j pg';
    }

    When I do an onmouseover and call the function, it doesn't work.
    BUT if I put the code in directly - it works!

    Why is this?
    I'm pulling my hair out.

    Any help would be appreciated.


    OM




  • Lasse Reichstein Nielsen

    #2
    Re: Why doesn't onmouseover work in a function?

    "OM" <OM@yahoo.com > writes:
    [color=blue]
    > Why doesn't a onmouseover function work in a function?[/color]

    I am not sure exactly what you mean.
    [color=blue]
    > (It's prob due to my code being wrong more than anything else!)
    >
    > I've got the following code (snippet):
    >
    > <!-- Begin[/color]

    You don't need HTML comments in Javascript.
    [color=blue]
    > var image0 = new Image(); image0.src = "blank.jpg" ;
    > var image1 = new Image(); image1.src = "map.jpg";
    > // End -->
    >
    > function swapTheImages()
    > {
    > image0.src='1.j pg'; image1.src='2.j pg'; image2.src='2.j pg';[/color]

    What døs image0, image1, and image2 refer to here. The first two
    proabably refers to the two global variables you created above.
    Changing them won't change anything on the page, unless you
    have put those Image elements into the page.
    [color=blue]
    > }[/color]
    [color=blue]
    > When I do an onmouseover and call the function, it doesn't work.
    > BUT if I put the code in directly - it works![/color]

    I guess we will have to see the code to answer that. It seems to be
    something about how you all the function, not the function itself,
    so we need to see how it is called.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • OM

      #3
      Re: Why doesn't onmouseover work in a function?

      Thanks for the reply.
      I managed to solve my problem.
      I used the following code:

      document["image0"].src = image1.src;

      That seems to have done the trick.
      BUT... I have another problem now.
      The size of the two images I'm swapping are different.
      When swap the images, the second bigger image gets made the same dimensions
      as the first.
      How do I stop this from happening?
      : (

      [color=blue][color=green]
      > > Why doesn't a onmouseover function work in a function?[/color]
      >
      > I am not sure exactly what you mean.
      >[color=green]
      > > (It's prob due to my code being wrong more than anything else!)
      > >
      > > I've got the following code (snippet):
      > >
      > > <!-- Begin[/color]
      >
      > You don't need HTML comments in Javascript.
      >[color=green]
      > > var image0 = new Image(); image0.src = "blank.jpg" ;
      > > var image1 = new Image(); image1.src = "map.jpg";
      > > // End -->
      > >
      > > function swapTheImages()
      > > {
      > > image0.src='1.j pg'; image1.src='2.j pg'; image2.src='2.j pg';[/color]
      >
      > What døs image0, image1, and image2 refer to here. The first two
      > proabably refers to the two global variables you created above.
      > Changing them won't change anything on the page, unless you
      > have put those Image elements into the page.
      >[color=green]
      > > }[/color]
      >[color=green]
      > > When I do an onmouseover and call the function, it doesn't work.
      > > BUT if I put the code in directly - it works![/color]
      >
      > I guess we will have to see the code to answer that. It seems to be
      > something about how you all the function, not the function itself,
      > so we need to see how it is called.[/color]


      Comment

      • The Plankmeister

        #4
        Re: Why doesn't onmouseover work in a function?

        > When swap the images, the second bigger image gets made the same
        dimensions[color=blue]
        > as the first.[/color]

        It's probably because your browser doesn't have a dynamic rendering engine.
        I have a similar problem that shows itself in Opera <= 6.
        Other browsers may suffer the same.
        Try it in another browser. I know it works fine in Opera7. (And it's a free
        download!)

        HTH.

        P.


        Comment

        Working...