calling multiple functions from a single event

R

reynoldscraigr

Hi All,

I am trying to call 2 functions from the 1 onMouseOver event on an
anchor tag, but I can't seem to get it to work. the following should
demonstrate

<a onMouseOver="ShowMenu('Menu3');AddMenuToHoldArray('Menu3')">Menu
3</a>


I have tried a number of variations, like adding "javascript:" in
front of the first call, and returning True of False from the first
function, but Icant get the second function to fire after the first
one has.

by using alerts, and wathcing what IS occuring, I know that the first
is being called, but the second isn't.

I did this once some years back, but I can't seem to rember how I did,
it, and none of the example that I have located have helped, so can
anyone point me in the right direction?

thanks
 
K

kaeli

I did this once some years back, but I can't seem to rember how I did,
it, and none of the example that I have located have helped, so can
anyone point me in the right direction?


I don't see anything wrong with the way you're calling the functions,
but if there is any error in AddMenuToHoldArray, the function won't do
anything. Did you try just putting that one in the mouseover by itself
to see if it works?

Also, javascript is case-sensitive - is the case correct in that name?

You can also try using Netscape 7 - they have a better debugger. Bring
up your page in NN, then type "javascript:" in the location bar after
you try the code and the function doesn't get called. If there was an
error, it will show up in the console.

Other than that, I'd need to see code.

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
R

reynoldscraigr

I know that the second function is ok, an that it is never even being
entered. To test that it was being entered I placed an alert() at the
start of it, and it runs when the sedond function is the only function
on the event, but not if there are 2 functions.

I assume the problem lies somewhere in the fact that due to return
values or some such, the second function is being ignored completely
 
R

Richard Cornford

I assume the problem lies somewhere in the fact that due to
return values or some such, the second function is being
ignored completely

The attribute code that you posted is syntactically correct and should
result in both functions being called. The return value of the first
function will have no influence on the execution of the second function
as it is just being discarded by the event handling code. But the fact
that you think it may have an influence demonstrates that you are not
qualified to judge the advice that you have been given. So, to re-state
Kaeli's advice:-

1. Check that the case (and maybe spelling) of the function
calls corresponds exactly with the identifiers in the
function definitions.
2. Determine if any error messages (and, if so, which) are
being generated.
3. Post the code of the functions that are being called.

Richard.
 
K

kaeli

I know that the second function is ok, an that it is never even being
entered.

If it isn't being entered, how can you know it's okay? :)
Call it by itself. Does it work? If you didn't test it alone to be sure
it works, it is more than likely NOT okay.
I assume the problem lies somewhere in the fact that due to return
values or some such, the second function is being ignored completely

Never ASSume. *g*
The return value of the first is irrelevant to the second.

Post some code or a link.

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
L

Lee

(e-mail address removed) said:
I know that the second function is ok, an that it is never even being
entered. To test that it was being entered I placed an alert() at the
start of it, and it runs when the sedond function is the only function
on the event, but not if there are 2 functions.

I assume the problem lies somewhere in the fact that due to return
values or some such, the second function is being ignored completely

You may not be as wrong as the other two posters seem to think,
if "some such" includes the possibility of an error exit from your
first function. Follow kaeli's advice to view the error messages
thrown from ShowMenu(), which would prevent your second function
from being invoked.
 
R

Richard Cornford

You may not be as wrong as the other two posters seem to
think, if "some such" includes the possibility of an error
exit from your first function. ...

Speculation on the reasons the second function does not get called may
include the first function directly calling the submit method of the
form, resulting in the current page being unloaded before the second
function gets a chance to execute and a similar effect resulting form
assigning a URL to the location object. Without being able to see the
code, speculation is just that, and ultimately Kaeli's original proposed
strategy will expose the real problem.

Richard.
 
R

reynoldscraigr

OK, thanks for the info so far guys, looking at the javascript console
I noticed that there was an exception in the first routine, where I
was going 1 spot too far through an array in a loop.

Now that I have fixed that, the second function is being called. Cool

Having established what the problem was an fixed it, I have another
question.

When getting the length of abd array, should I be using the .length
property, or a the arrayLength property?

they both seem to work, or at least I'm not getting exceptions :)

ie

for (i=0;i<=menus.length-1;i++) {
HideMenu(menus);
}

or

for (i=0;i<=menus.arrayLength-1;i++) {
HideMenu(menus);
}
 
L

Lasse Reichstein Nielsen

When getting the length of abd array, should I be using the .length
property, or a the arrayLength property?

There is no arrayLength property in any version of Javascript that
I know of.
they both seem to work, or at least I'm not getting exceptions :)

Sure, the last one counts while (i <= undefined), which is always
false. No action, no chance of exceptions :)

/L
 
R

reynoldscraigr

There is no arrayLength property in any version of Javascript that
I know of.


Sure, the last one counts while (i <= undefined), which is always
false. No action, no chance of exceptions :)

well, that answers that one, thanks a lot.

Now off to see what else I have managed to foget over the last couple
of years :)
 
L

Lee

Richard Cornford said:
Speculation on the reasons the second function does not get called may
include the first function directly calling the submit method of the
form, resulting in the current page being unloaded before the second
function gets a chance to execute and a similar effect resulting form
assigning a URL to the location object. Without being able to see the
code, speculation is just that, and ultimately Kaeli's original proposed
strategy will expose the real problem.

I was simply pointing out that he was correct to assume that
something in the way that the first function returns may be
causing the problem. It is highly likely to be an error in
the first function. That's not just a random guess. It's
been a very common cause of such error reports in the past.
It is very unlikely that he submits the form from a function
called ShowMenu(), and doesn't report other symptoms.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top