[This article should be considered deprecated. The code represented has been improved, extended and made available as the DP_SharePoint Function Library. All future effort will be applied there.]
The first article in this series dealt with obtaining a reference to a SharePoint field in Add and Edit forms. One of the most common reasons to head down this path is to add custom validation to fields. Often this requires adding events to (in the case of most fields) the onchange or (in the case of buttons) the onclick events of the fields. Simply setting the event handler directly would work, but will eliminate any currently enabled handlers (such as those defined internally to SharePoint).
Instead I created two functions to abstract the standardized addEventListener() and (for older IE browsers) the attachEvent() methods. They accept a reference to an HTML element (in this case a SharePoint form field), an event type and a function name to call when the event is fired. The first adds an event to the passed element and the second (which is included for balance but which I’ve honestly never actually used) removes it.