Why doesn't onmouseover work in a function?

O

OM

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.jpg'; image1.src='2.jpg'; image2.src='2.jpg';
}

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
 
L

Lasse Reichstein Nielsen

OM said:
Why doesn't a onmouseover function work in a function?

I am not sure exactly what you mean.
(It's prob due to my code being wrong more than anything else!)

I've got the following code (snippet):

<!-- Begin

You don't need HTML comments in Javascript.
var image0 = new Image(); image0.src = "blank.jpg";
var image1 = new Image(); image1.src = "map.jpg";
// End -->

function swapTheImages()
{
image0.src='1.jpg'; image1.src='2.jpg'; image2.src='2.jpg';

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.
When I do an onmouseover and call the function, it doesn't work.
BUT if I put the code in directly - it works!

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
 
O

OM

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?
: (
 
T

The Plankmeister

When swap the images, the second bigger image gets made the same
dimensions
as the first.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,093
Messages
2,570,607
Members
47,226
Latest member
uatas12

Latest Threads

Top