Connecting Tech Pros Worldwide Help | Site Map

Why doesn't onmouseover work in a function?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 10:32 AM
OM
Guest
 
Posts: n/a
Default 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.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





  #2  
Old July 20th, 2005, 10:32 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default 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.jpg'; image1.src='2.jpg'; image2.src='2.jpg';[/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.'
  #3  
Old July 20th, 2005, 10:33 AM
OM
Guest
 
Posts: n/a
Default 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.jpg'; image1.src='2.jpg'; image2.src='2.jpg';[/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]


  #4  
Old July 20th, 2005, 10:35 AM
The Plankmeister
Guest
 
Posts: n/a
Default 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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.