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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business