calling multiple functions from a single event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • reynoldscraigr@hotmail.com

    #1

    calling multiple functions from a single event

    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="Sh owMenu('Menu3') ;AddMenuToHoldA rray('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

  • kaeli

    #2
    Re: calling multiple functions from a single event

    In article <a8a4163842cf06 d28c8a427771a9a f26@news.terane ws.com>,
    reynoldscraigr@ hotmail.com enlightened us with...[color=blue]
    >
    > 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?
    >[/color]


    I don't see anything wrong with the way you're calling the functions,
    but if there is any error in AddMenuToHoldAr ray, 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.


    -------------------------------------------------

    Comment

    • reynoldscraigr@hotmail.com

      #3
      Re: calling multiple functions from a single event

      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


      On Tue, 28 Oct 2003 07:20:00 -0600, kaeli
      <infinite.possi bilities@NOSPAM att.net> wrote:
      [color=blue]
      >In article <a8a4163842cf06 d28c8a427771a9a f26@news.terane ws.com>,
      >reynoldscraigr @hotmail.com enlightened us with...[color=green]
      >>
      >> 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?
      >>[/color]
      >
      >
      >I don't see anything wrong with the way you're calling the functions,
      >but if there is any error in AddMenuToHoldAr ray, 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
      >-------------------------------------------------[/color]

      Comment

      • Richard Cornford

        #4
        Re: calling multiple functions from a single event

        <reynoldscraigr @hotmail.com> wrote in message
        news:c839039a25 20d543f86f1d2da 248950a@news.te ranews.com...
        <snip>[color=blue]
        >I assume the problem lies somewhere in the fact that due to
        >return values or some such, the second function is being
        >ignored completely[/color]

        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.


        Comment

        • kaeli

          #5
          Re: calling multiple functions from a single event

          In article <c839039a2520d5 43f86f1d2da2489 50a@news.terane ws.com>,
          reynoldscraigr@ hotmail.com enlightened us with...[color=blue]
          > I know that the second function is ok, an that it is never even being
          > entered.[/color]

          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.
          [color=blue]
          >
          > I assume the problem lies somewhere in the fact that due to return
          > values or some such, the second function is being ignored completely
          >
          >[/color]

          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.


          -------------------------------------------------

          Comment

          • Lee

            #6
            Re: calling multiple functions from a single event

            reynoldscraigr@ hotmail.com said:[color=blue]
            >
            >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[/color]

            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.

            Comment

            • Richard Cornford

              #7
              Re: calling multiple functions from a single event

              "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
              news:bnms2o02er 8@drn.newsguy.c om...
              <snip>[color=blue]
              >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. ...[/color]

              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.


              Comment

              • reynoldscraigr@hotmail.com

                #8
                Re: calling multiple functions from a single event

                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.l ength-1;i++) {
                HideMenu(menus[i]);
                }

                or

                for (i=0;i<=menus.a rrayLength-1;i++) {
                HideMenu(menus[i]);
                }

                On Tue, 28 Oct 2003 11:54:49 GMT, reynoldscraigr@ hotmail.com wrote:
                [color=blue]
                >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="Sh owMenu('Menu3') ;AddMenuToHoldA rray('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[/color]

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: calling multiple functions from a single event

                  reynoldscraigr@ hotmail.com writes:
                  [color=blue]
                  > When getting the length of abd array, should I be using the .length
                  > property, or a the arrayLength property?[/color]

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

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

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • reynoldscraigr@hotmail.com

                    #10
                    Re: calling multiple functions from a single event

                    On 29 Oct 2003 12:49:04 +0100, Lasse Reichstein Nielsen
                    <lrn@hotpop.com > wrote:
                    [color=blue]
                    >reynoldscraigr @hotmail.com writes:
                    >[color=green]
                    >> When getting the length of abd array, should I be using the .length
                    >> property, or a the arrayLength property?[/color]
                    >
                    >There is no arrayLength property in any version of Javascript that
                    >I know of.
                    >[color=green]
                    >> they both seem to work, or at least I'm not getting exceptions :)[/color]
                    >
                    >Sure, the last one counts while (i <= undefined), which is always
                    >false. No action, no chance of exceptions :)[/color]

                    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 :)
                    [color=blue]
                    >
                    >/L[/color]

                    Comment

                    • Lee

                      #11
                      Re: calling multiple functions from a single event

                      Richard Cornford said:[color=blue]
                      >
                      >"Lee" <REM0VElbspamtr ap@cox.net> wrote in message
                      >news:bnms2o02e r8@drn.newsguy. com...
                      ><snip>[color=green]
                      >>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. ...[/color]
                      >
                      >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.[/color]

                      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.

                      Comment

                      Working...