File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to attach event with parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "How to attach event with parameter" Watch "How to attach event with parameter" New topic
Author

How to attach event with parameter

Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
I was reading the MSDN library and found that we can attach event to an object with event properties :

object.event=function;
eg:
function setHeadStyle() {
window.event.srcElement.style.color = "green";
}
document.all.MyHeading.onzclick=setHeadStyle;

or, we could use attachEvent method :

object.attachEvent(event, function);
eg:
document.all.MyHeading.attachEvent('onkeypress', setHeadStyle);

We can see that the function (setHeadStyle) didn't receive parameter.
I can't find how to pass parameter to the function.
Anyone know how?

Susilo
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
A Mess:
http://oldlook.experts-exchange.com:8080/Web/Web_Languages/JavaScript/Q_20785033.html
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 411
Are you looking for something like that?

on_click = new Function("setHeadStyle('verycoolstyle',32);")
[ May 18, 2004: Message edited by: Yuriy Fuksenko ]
Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
Both replies worked well. Thanks guys!
 
 
subject: How to attach event with parameter
 
Threads others viewed
how to get the name?
console.log function not working.
how to identify duplicate form elements with same name in a funcation
STRUTS Passing parameter to DHTMLSuite.modalMessage()
JQuery:- Adding event to element not present currrently
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com