Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to next two OnMouseOvers in one link... 1

Status
Not open for further replies.

jonnyGURU

IS-IT--Management
Aug 19, 2004
138
US
I know this must be as easy as having the right separator in place, but....

I've got one link, one onMouseOver. I want two things to happen during the onMouseOver: Load a link in an iframe and change the image that is the link (sounds busy, eh?)

The two work separately. I can get the image to change onMouseOver and I can load the iFramce onMouseOver, but not both at the same time.

What am I doing wrong? What's the separator? I've done onMouseOver="'one event','other event'" and put two onMouseOvers in the tag and separated with a semi-colon... am I asking for the impossible?

Dispensing quality rants and mishaps since 1999:
 
no, you're not asking for anything even remotely near impossible ;).

Code:
<img src="blah.gif" onmouseover="firstlineofcode[red]; [/red]this.src='other.gif';" />

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Hmm... I tried that and now it works in Mozilla, but not IE. :p

Boy! That's basackwards!

Here's what I got:

<a href="Avaya4600.htm" target="ifrm"
onMouseOver="over('4600','2420mouseon.gif'); loadIframe('ifrm', this.href)"
onMouseOut="out('4600','2420mouseoff.gif')">
<img src="2420mouseoff.gif" border=0 name="4600" width=600 height=30>
</a>

This works in Netscape/Mozilla/Firefox. I've replaced that semicolon with a comma and added a second "onmouseover=" inside the quotes and it continues to work, but never in IE. :(


Dispensing quality rants and mishaps since 1999:
 
Just call your two onMouseOver events from a function, and call that function from your onMouseOver command:
Code:
function myMO() {
   over('4600','2420mouseon.gif'); 
   loadIframe('ifrm', this.href);
}
...
<a href="Avaya4600.htm" target="ifrm"
onMouseOver="myMO();" 
onMouseOut="out('4600','2420mouseoff.gif')">
<img src="2420mouseoff.gif" border=0 name="4600" width=600 height=30>
</a>

Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 
I'm not sure why you keep reverting to putting commas between lines of code, as that is not valid JavaScript. Can we see the code in your functions? I have a feeling it may have something to do with that.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
I have a Netscape JavaScript book I've been using since 1996 that says where I'm using my comma's is completely appropriate.

My functions work perfectly in both Netscape and IE by themselves. They only cease to work when I nest the two functions together.

Dispensing quality rants and mishaps since 1999:
 
From Netscape's own JavaScript primer: "Commas separate parameters and features within a feature list."

That said, please just remember... The "over" and "loadIframe" functions work in both Netscape and IE without issue. They just don't work simultaneously is IE. It's as if the syntax to nest the two is incorrect, although I can't see the issue, especially if I define a function, like MyMO() as in tsdryden's example.

Dispensing quality rants and mishaps since 1999:
 
You need to understand what parameters are, and how they differ from semi-colons. You're fighting a losing battle here.

Code:
function showAlerts(str1, str2) {
    alert(str1);
    alert(str2);
}

function showMoreAlerts(str3, str4) {
    alert("second function " + str3);
    alert("second function " + str4);
}

<input type="button" onclick="showAlerts('hi', 'bye'); showMoreAlerts('hi', 'bye');" />
Trust me on this one, you [red]cannot[/red] separate two lines of JavaScript with commas.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
parameters are variables that you pass to functions. lines of code are separate pieces of code that each perform separate functionality.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
I AM seperating parameters. Not code, not lines. I appreciate your interest, but I don't think you understand what I'm doing. I can see that now that I see your example. That's not what I'm doing.

Let me throw this up here so we can get past this and make this work. ;)

4600 is the name of the image and 2420mouseoff.gif is the name of the image that I am passing to the function called "over." My function then does this:

function over(imgname,imgsrc) {
document
.src=imgsrc;
}

Just a simple image swap.

The loadIframe works in a similar manner. I'm passing the name of the iFrame and the content source to the function via iFrm and a URL (or this.url if the function resides in an anchor tag.) So you can see, I'm not seperating functions with a comma. The only time I did do this is when I checked with HTMLGoodies and they showed something similar to this:

onMouseOver="function1(), onmouseover=function2();"

This worked in their example which was a status bar change and a BGColor change and it worked in both IE and Netscape, but it didn't work with my two functions in IE. Only in Netscape. Since then, I've taken the comma back out but I still have the same problem.

The two functions work separately, but do not work together in the same link.

Thanks! :D

Dispensing quality rants and mishaps since 1999:
 
If you can make the image's id "4600" I suggest you do that as well. Let me say though that it's not a good idea to give names/ids to elements that are numbers (or at least start with numbers).

So, you give the image an id of "4600" although "i4600" would be better.

Then you do this:

Code:
function over(imgname,imgsrc) { 
    document.getElementById(imgname).src=imgsrc; 
}

what part of the code isn't working?

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
The code is working. That's what I'm saying. The codes work one at a time. They don't work if I put the two together in one onMouseOver event.

In I.E., only the default image shows. Nothing works IF I put the two functions together in one onMouseOver (or create a function with both functions nested within), but they DO work if I have only one or the other function in place.



Dispensing quality rants and mishaps since 1999:
 
the only thing left is showing the code. we've given you many possible answers, yet you continue to say the code doesn't work, without providing the code. if you provide the code, i'll be able to see what's wrong on my own machine.

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Just an update. Sorry I hadn't been back. The problem was all in the name of the image. JavaScript didn't like passing a number for a string. I did as you (cLFlaVA) suggested and threw an "i" behind it and it worked. Go figure that a stupid image name, based on a part number, would screw my whole script. :(


Dispensing quality rants and mishaps since 1999:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top