• 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

Dynamically change events

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to change the onclick event of a particular element in my html code dynamically. I know that this can be done if there is no parameters by simply omitting the brackets at the end. However, I'm having problems getting it to work when the method takes parameters. Does anybody know how to do this?

Thanks,

Reza
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
------.onclick = function(){alert('a');}

Eric
 
R Mousavi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I have tried your suggestion, however it seems that it will not work for me as it tries to evaluate the parameters of the function when it is run. I need the parameters to be evaluated when the events are being set and the function run when the event occurs, looking at the following piece of code might explain further what im trying to do.

The function below takes the tag and the class you are using and changes all of their onclick events to perform a specific action. I have also tried using evall(elems[i].id), but this will make all of the ids equal to the last one passed.


(p.s. the kk on the onclickk and ll on evall are because it wouldnt let me submit the post)
Thanks,
Reza
 
reply
    Bookmark Topic Watch Topic
  • New Topic