By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,460 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,460 IT Pros & Developers. It's quick & easy.

Why doesn't onmouseover work in a function?

P: n/a
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


Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"OM" <OM@yahoo.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
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?
: (

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.

Jul 20 '05 #3

P: n/a
> 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.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.