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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint