• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to Attach event in DOM or javascript having parameters

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic