spacer
Yehuda Shiran January 9, 2001
Multiple Events in IE 5.x
Tips: January 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

Internet Explorer 5.0 introduced a way to attach more than one event of the same type to an element. Use the attachEvent() method for that:

document.element.attachElement(eventNameString, functionPointer)

The following code creates a button and attaches two onclick event handlers to it:

<FORM>
<INPUT ID="counter1" STYLE="position:relative; left:10px" TYPE="button" VALUE="Click Me in IE 5.x">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
<!--
var obj = document.getElementById('counter1');
var xlocation = parseInt(obj.style.left);
document.getElementById('counter1').attachEvent("onclick", firstClick);
document.getElementById('counter1').attachEvent("onclick", secondClick);

function firstClick() {
  alert("first click");
}

function secondClick() {
  alert("second click");
}

// -->
</SCRIPT>

Play around with it now in Internet Explorer 5.x. Observe the two alert boxes for the two event handlers:

For more on the Internet Explorer event model, go to Column 10, The Internet Explorer Event Model.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Workers Say Telework Is More Productive, Bosses Not So Sure · Kingston Debuts Power-Saving Memory Upgrades · Social Networking is King: Facebook Edges Google