Another JS q
by "Hilma" <Hilma(at)hilma.freeserve.co.uk>
|
Date: |
Thu, 23 May 2002 10:41:38 +0100 |
To: |
<hwg-techniques(at)hwg.org> |
References: |
brett |
|
todo: View
Thread,
Original
|
|
Yes, yet another JS q - hope you can help :-)
I have found out (from my trusty O'reilley JS book) how to assign a function
to an event handler:
----------------------------------------------------------------------------
----------------------
function MyonClick( myMsg)
{
alert ("ON CLICK " )
alert ("ON CLICK with myMsg = " + myMsg)
}
----------------------------------------------------------------------------
----------------------
function AddmyClick()
{
for (var i=0 ; i< document.links.length ; i++)
{
document.links[i].onclick = MyonClick ;
}
}
----------------------------------------------------------------------------
----------------------
(and i call "AddmyClick" in the body onLoad event).
This works fine, except of course, "myMsg" is undefined.
But, i cannot figure out (assuming it is possible) how to pass a parameter
(argument?) to the event;
I have tried all of the following unsuccessfully:
document.links[i].onclick = MyonClick ("hello");
document.links[i].onclick = MyonClick , "This is eddy" ;
document.links[i].onclick = MyonClick "Your shipboard computer" ;
But none will allow me to display the message from the onClick event.
*Can* a parameter be assigned to an event handler in this way; and if so,
how?
Many thanks!
Hilma
--x-----
i wasnt if
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA