SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Dynamic HTML :

Previous DiscussionNext Discussion
 Obsessive/Compulsive re: Events

Friends,

I fear I'm losing site of the forest, but...in a project, I've created
three functions to handle events:

addListeners()
addEvent(element, eventType, functionName)
eventHandler(e)

and an XML file to store event info for the elements:

<root>
 <element id='txt09'>
  <event name='blur' />
  <event name='focus' />
  <event name='keydown' />
 </element>
 <element id='txt10'>
  <event name='blur' />
  <event name='focus' />
  <event name='keydown' />
 </element>
 <element id='txt11'>
  <event name='blur' />
  <event name='focus' />
  <event name='keydown' />
 </element>
 <element id='spanAllItem'>
  <event name='dblclick' />
 </element>
 <element id='spanDocItem'>
  <event name='dblclick' />
 </element>
 <element id='thDocItem'>
  <event name='click' />
  <event name='mouseover' />
  <event name='mouseout' />
 </element>
</root>

addListeners loads the XML file, parses it, and calls addEvent to assign
the event to the element(s) found within.

eventHandler is invoked when any of the elements fire an event; it decodes
the element and through switch() blocks determines what to do.

Am I taking things too far, when I could just as well code 'onClick()',
'onBlur()', etc. directly into the HTML element declarations?

Or does abstracting things in this way make sense?

tia

Started By Badotz on Jul 20, 2005 at 9:36:00 AM

5 Response(s) | Reply

Earlier Replies | Replies 2 to 5 of 5 | Later Replies
ctcrmcou on Jul 20, 2005 at 10:15:35 AM (# 2)
This message has been edited.

It depends how you are generating your HTML.  If you are doing it from the server, your functions can easily manage the repetition, and make debugging easier.  You don't have to keep referencing another source, and deal with the exceptions all the time.  It's neat and clean, however, but not really practical in a dynamic environment.  And think about the fact that you would have to always update changes in two places, not just one.

clarify edit:  By "your functions", I mean you write functions that render your HTML script that are repeated many times, like buttons that have many attributes and handlers, not the functions you referenced in your question.


Badotz on Jul 20, 2005 at 10:30:52 AM (# 3)

ctcrmcou: "...two places, not just one."  Referring to the eventHandler code and the XML file; but I would still have to change two items, wouldn't I?  #1 the HTML element and #2 the code to handle the event?  Unless I'm misunderstanding your inference...the depth of my ignorance is boundless ;-)

This all happens client-side (currently); it was more of an experiment than anything else.  I just wondered how far I should go with it.  I tend to over-engineer things (as my wife is fond of saying).


ctcrmcou on Jul 20, 2005 at 10:52:16 AM (# 4)

If it's all client side, then do what you can to be efficient.  But two place refers to two different files, back and forth, not on the same line of HTML script.


Badotz on Jul 20, 2005 at 11:06:52 AM (# 5)

Understood.  Perhaps it needs a second look, but I'll let it stew for a day or two.  Thanks for the feedback.


Earlier Replies | Replies 2 to 5 of 5 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.