473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Trouble with onMouseOver and onMouseOut.

Daz
Hi everyone.

I think my problem is a simple one, but I am completely baffled as to
how to pull it off.

I have a piece of code like so...
document.write(
"<img id=\"slideshow_toggle\" src=\"img/stop_slideshow.png\" "
+ "onMouseOver=\"src='./img/stop_slideshow_hover.png'\" "
+ "onMouseOut=\"src='./img/stop_slideshow.png'\" "
+ "onClick=\"slideshow_button()\" />&nbsp;"
);

I have a function that is meant to change the button. It should be
changed to a different image of the same button onMouseOver, then
changed back onMouseOut. onClick, the button should change completely,
but still have the onMouseOver and onMouseOut properties, only using
slightly different images.

Here is the function...

function slideshow_button() {
var slideshow_toggle = d.getElementById("slideshow_toggle");
if (slideshow_toggle.src.match(/stop/)) {
slideshow_toggle.src = './img/start_slideshow.png'
slideshow_toggle.onMouseOver =
"src='./img/start_slideshow_hover.png'"
slideshow_toggle.onMouseOut = "src='./img/start_slideshow.png'"
}
else {
slideshow_toggle.src = './img/stop_slideshow.png'
slideshow_toggle.onMouseOver =
"src='./img/stop_slideshow_hover.png'"
slideshow_toggle.onMouseOut = "src='./img/stop_slideshow.png'"
}
}

Everything the picture changes when I click the button, but for some
reason, the wrong onMouseOut event kicks in, and when I move my mouse
from the image, it changes back to the wrong image. I am sure there is
a simple solution, but I just can't seem to find it. I have tried
removing the onMouse events from the <imgelement itself, and I have
tried using them but leaving the args blank (ie. onMouseOver="" and
onMouseOut=""). Just as I suspected, it didn't work, but it was worth a
try. If anyone can shed any light on the subject, I would very much
appreciate it. Remember. in all, there are 4 images, (2 sets of 2). The
onMouse events switch from on to the other in the appropriate set of 2,
and the onClick should switch to the other set of 2 images.

Many thanks.

Daz.

Nov 7 '06 #1
2 2612

Daz wrote:
Hi everyone.

I think my problem is a simple one, but I am completely baffled as to
how to pull it off.

I have a piece of code like so...
document.write(
"<img id=\"slideshow_toggle\" src=\"img/stop_slideshow.png\" "
+ "onMouseOver=\"src='./img/stop_slideshow_hover.png'\" "
+ "onMouseOut=\"src='./img/stop_slideshow.png'\" "
+ "onClick=\"slideshow_button()\" />&nbsp;"
);
I don't understand why you are using document.write. Even if there's a
point (and there are valid reasons for doing it) you should just post
the HTML it generates, unless you're having problems with the
document.write() itself.

The use of " />" as a closing tag indicates that you think you are
using XHTML. In that case, not only must your attribute names must be
all lower case but document.write() should not work at all. If you
aren't using XHTML, stick to valid HTML 4.01 strict.

I have a function that is meant to change the button. It should be
changed to a different image of the same button onMouseOver, then
changed back onMouseOut. onClick, the button should change completely,
but still have the onMouseOver and onMouseOut properties, only using
slightly different images.

Here is the function...
How about something like:

<img src="button_stop_out.jpg"
onmouseover="toggleImage(this, event);"
onmouseout="toggleImage(this, event);"
onclick="toggleImage(this, event);"
>
And the function:

function toggleImage (el, e) {
var eType = e.type;
if (/mouseover/.test(eType)) {
el.src = el.src.replace(/_out/,'_over');
} else if (/mouseout/.test(eType)) {
el.src = el.src.replace(/_over/,'_out');
} else if (/click/.test(eType)) {
el.src = el.src.replace(/_start/,'_stop');
}
}

and name the images:

blah_start_out.jpg
blah_start_over.jpg
blah_stop_out.jpg
blah_stop_over.jpg
__
Fred

Nov 8 '06 #2
Daz

Fred wrote:
Daz wrote:
Hi everyone.

I think my problem is a simple one, but I am completely baffled as to
how to pull it off.

I have a piece of code like so...
document.write(
"<img id=\"slideshow_toggle\" src=\"img/stop_slideshow.png\" "
+ "onMouseOver=\"src='./img/stop_slideshow_hover.png'\" "
+ "onMouseOut=\"src='./img/stop_slideshow.png'\" "
+ "onClick=\"slideshow_button()\" />&nbsp;"
);

I don't understand why you are using document.write. Even if there's a
point (and there are valid reasons for doing it) you should just post
the HTML it generates, unless you're having problems with the
document.write() itself.

The use of " />" as a closing tag indicates that you think you are
using XHTML. In that case, not only must your attribute names must be
all lower case but document.write() should not work at all. If you
aren't using XHTML, stick to valid HTML 4.01 strict.

I have a function that is meant to change the button. It should be
changed to a different image of the same button onMouseOver, then
changed back onMouseOut. onClick, the button should change completely,
but still have the onMouseOver and onMouseOut properties, only using
slightly different images.

Here is the function...

How about something like:

<img src="button_stop_out.jpg"
onmouseover="toggleImage(this, event);"
onmouseout="toggleImage(this, event);"
onclick="toggleImage(this, event);"
>

And the function:

function toggleImage (el, e) {
var eType = e.type;
if (/mouseover/.test(eType)) {
el.src = el.src.replace(/_out/,'_over');
} else if (/mouseout/.test(eType)) {
el.src = el.src.replace(/_over/,'_out');
} else if (/click/.test(eType)) {
el.src = el.src.replace(/_start/,'_stop');
}
}

and name the images:

blah_start_out.jpg
blah_start_over.jpg
blah_stop_out.jpg
blah_stop_over.jpg
__
Fred
Superb! Thank you very much. I am just getting to grips with JavaScript
and it seems to be really hard to find a decent breakdown of what
functions and subfunctions are available. Since then I have found
http://research.nihonsoft.org/javasc...sref/index.htm which seems to
be a little Netscape orientated, but nonetheless, exceptionally good
and seems to cover just about everything.

Thanks again for your help.

Daz.

Nov 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim | last post by:
Hope someone in the big wide world can help... What I want to do is have an image slideshow which automatically scrolls through a series of images very fast, then pauses when you move your mouse...
1
by: christian9997 | last post by:
Hi I was trying to create a page where a SubMenu would appear when the user moved the mouse over an item of a Menu (= Table Cell <TD>). Unfortunately there seems to be a problem; the onMouseOver...
4
by: laurie | last post by:
Hi. I have a DIV section that has many thumbnail images inside it. I have a DIV so all images can fit in a row and the horizontal scroll bar is used to move the thumbnails from left to right. ...
7
by: Richard | last post by:
I know I can have like <a href="#" onclick="dothis" onmouseover="dothat"> But how do you properly code two mouseover's in one statement? <a href="#" onmousever="dothis" onmouseover="dothat"> As...
3
by: Rob Roberts | last post by:
I'm using .NET 2.0 and C# on a web site, and I'm trying to use the onmouseover and onmouseout events to do a rollover effect on an asp.net button. I've tried manually adding the events to the...
2
by: MrCode2k | last post by:
Hello, Trying to do: I just want a table that I can scroll and that has fixed headers. Problem: I got it to work but when I added the onmouseover event it didn't work anymore....
7
by: MrCode2k | last post by:
Hello, Trying to do: I just want a table that I can scroll and that has fixed headers. Problem: I got it to work but when I added the onmouseover event it didn't work anymore....
3
by: oopaevah | last post by:
I have written some dom code to create a list of divs, each with it's own id. I want to set the onmouseover and onmouseout events to highlight the div when the mouse is over it. However I cannot...
4
by: bgold12 | last post by:
Hey, I have kind of a weird problem. I have a span that I'm intentionally overflowing a table cell (<td>), so that it stretches over the table cells to the right of the parent table cell. I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.