wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how to Attach event in DOM or javascript having parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to Attach event in DOM or javascript having parameters" Watch "how to Attach event in DOM or javascript having parameters" New topic
Author

how to Attach event in DOM or javascript having parameters

Parshuram Walunjkar
Ranch Hand

Joined: Jan 02, 2002
Posts: 31
Hi All,
I am actually generating new rows using javascript on a click of a button but my problem is to attach an event to this generated row .
I have used this method : obj.attachEvent("eventname",function) but all in vain.Please kindly suggest me .
Parshu.


Parshuram Walunjkar
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
Originally posted by Parshuram Walunjkar:
Hi All,
I am actually generating new rows using javascript on a click of a button but my problem is to attach an event to this generated row .
I have used this method : obj.attachEvent("eventname",function) but all in vain.Please kindly suggest me .
Parshu.

If you want to use a parameter in the function, you have to have define the function that you pass as a parameter to attachEvent as the function call.
e.g. your function is:

I think - it's been a while - or something very similar. You might need a function name in there too.
Good luck!
Adam


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
big dog
Greenhorn

Joined: Feb 20, 2004
Posts: 1
Hi there,
here is some code I just wrote:
// event of button onmouseout
function normalstate(){
change.style.backgroundColor= 'deepskyblue';
}
//event of button onclick
function doit(this){
alert(this.id);
}
var buttonframe = document.createElement('div');//creating a dividerelement
buttonframe.setAttribute('id', 'dummy');//with the id of the elementgroup
buttonframe.setAttribute('className', 'buttonframe');//setting its class to buttonframe in the .CSS
document.childNodes[1].childNodes[1].appendChild(buttonframe);//find the body node of the document and append the frame
var frame = document.getElementById('dummy');//referring to the element by its new id
frame.style.top = fromtop;//setting th position offset from top
frame.style.left = fromleft;//setting th position offset from left
var button = document.createElement('div');//creating the divider button element
button.setAttribute('id', 'test');//setting its id
button.setAttribute('className', 'button');//setting the class name from the .CSS style sheet
document.getElementById('dummy').appendChild(button);//refer to the frame element by its id and append the button
var change = document.getElementById('test');//get the button element by its id and position it
change.style.top = "0"

document.getElementById("test").attachEvent("onmouseover",highlite);//give it an event onmouseover
document.getElementById("test").attachEvent("onmouseout",normalstate);//give it an event onmouseout
document.getElementById("test").attachEvent("onclick",doit);//give it an event onmouseout

Hope this will help you
bigdog jstacher@econophone.ch
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Welcome BIG DOG,
First off you replied to a post from May 2002. I highly doubt the person needs the answer 22 months later.
Secondly
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thank You
Eric and the rest of the JavaRanch Staff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to Attach event in DOM or javascript having parameters
 
Similar Threads
How to Invalidate Session
Submit dynamically created form using jQuery Form plugin
Need to call javascript function from an html page.
problem with Invalid direct reference to form login page
jQuery form submit using Form plugin not working