• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Recommended way to keep multiple event handlers?

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

Could anyone please recommend a design approach for keeping more than 1 event handler, for the same event ?
In particular, could you keep such handlers un-aware of each other?

Simplified example:
Say I started off with 2 independent requirements for a text input's "onkeyup()" :
- Some text-inputs should only allow lower-case letters
- Other(!) text-inputs should sound a 'beep' while tying.
Then this works:



However, later the requirements evolve, and *some* text-inputs need both effects (beep & lowercase). While other fields need a single effect (eg. just beep).
Of course, I could write a new 'onkeyup()' function that performs both actions (beep and lowercase).
But I really wish I could make it cleaner:


In real life my 'Handlers' are more complex, there are more Handlers and more combinations.
What is the best way to allow such combinations, while keeping my handlers un-aware of each other?

Thanks very much!

[ March 15, 2007: Message edited by: Sol Mam-Orn ]
[ March 15, 2007: Message edited by: Sol Mam-Orn ]
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using DOM Level 0 Event handling, you are pretty much out of luck. At least not without a lot of mess.

Using the DOM Level 2 Event Model allows you to register multiple and independent handlers. The drawback is that it's browser dependent: there's the standard W3C way, and the Microsoft "we don't need no stinking standards" way.

Use of a library such as Prototype or jQuery eases the pain considerably.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this: http://www.pascarello.com/examples/testRegister.html

Eric
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic