Re: Another JS q

by "Hilma" <Hilma(at)hilma.freeserve.co.uk>

 Date:  Thu, 23 May 2002 15:10:06 +0100
 To:  "tim booker" <tim(at)yaffle.org>,
<hwg-techniques(at)hwg.org>
 References:  yaffle
  todo: View Thread, Original

>
> document.links[i].onclick = function() { MyonClick('hello') }
>
>
> Should do it.
>
> HTH,
> Tim
>

Many thanks for that -
It sort-of works, but not quite :-)
At least - my usage of it doesn;t do what i really want done, which implies
mis-use :-(

I have a work-around for what i want to do (which is to pass an ID), which
means going through an "extra" function;
So the code i have works, but is probably not the best way to do what i want
to do.

So, only if you have time :-)

My code:
----------------------------------------------------------------------------
---------------------------------
//Add the MouseOver event to all main Nav Menu items
function AddonMouse()
{
  var myId;
  for (var i=0 ; i< document.links.length ; i++)
    if (document.links[i].className=="NavButton")
      {
      document.links[i].onmouseover = MyonMouse
     }
 }
----------------------------------------------------------------------------
---------------------------------
function MyonMouse()
{
   ToggleSub(this.id)
}
----------------------------------------------------------------------------
---------------------------------

function ToggleSub(myID)
{
 alert(myID)
 *** myID IS  the required  menu ID **
}
----------------------------------------------------------------------------
---------------------------------

Which works, but is clumsy (and i don;t altogether understand what is going
on -  only that ToggleSub is receiving the required MenuID whenever i do a
mouseover on any of the navigation elements, so my code works as planned).

Trying your suggestion:

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

//Add the MouseOver event to all main Nav Menu items
function AddonMouse()
{
  var myId;
  for (var i=0 ; i< document.links.length ; i++)
    if (document.links[i].className=="NavButton")
      {

     // this always accesses the *last* menu item

      myId = document.links[i].id;
      document.links[i].onmouseover =  function() { ToggleSub(myId) }

///equivalent to  document.links[i].onmouseover =  function() {
ToggleSub(document.links[i].id) }

     }

}

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

function ToggleSub(myID)
{
   alert(myID)
***   myID is  The last of the (10) nav buttons  ***
***  ie. the last of : document.links[i].className=="NavButton")
***  not the one that the mouse was over ***
}

----------------------------------------------------------------------------
---------------------------------
As i say- i have a work-around; but i don;t really understand it, so i'd
appreciate further explanation of my code, and
why your code doesn;t work in this instance, -  but no panic!

Many many thanks -

Hilma
-x-----

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA