spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column10


Standard Event Handlers

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

Internet Explorer 4.0x supports the two most basic event handler methods:

  • HTML attribute
  • Property assignment

Consider the following form definition:

<FORM NAME="myForm">
<INPUT TYPE="button" NAME="myButton" VALUE="click here">
</FORM>

When you click the button, nothing happens because no script or function is attached to its click event. For instance, you could associate it with a function that generates an alert dialog box by placing an onClick event handler script in the body of the tag:

<SCRIPT LANGUAGE="JavaScript">
<!--

function myAlert() {
  alert("Thank you for clicking the button.");
}

// -->
</SCRIPT>

<FORM NAME="myForm">
<INPUT TYPE="button" NAME="myButton" 
       VALUE="click here" onClick="myAlert()">
</FORM>

For more information on this approach, take a look at the event handler page in Column 9. Once you've read it, click the browser's Back button to return.

Another way to associate a function with a specific event is to assign its reference to the object's event handler property:

<SCRIPT LANGUAGE="JavaScript">
<!--

function myAlert() {
  alert("Thank you for clicking the button.");
}

// -->
</SCRIPT>

<FORM NAME="myForm">
<INPUT TYPE="button" NAME="myButton" VALUE="click here">
</FORM>

<SCRIPT LANGUAGE="JavaScript">
<!--

document.myForm.myButton.onclick = myAlert;

// -->
</SCRIPT>

Once again, if you aren't familiar with this technique, I strongly recommend reading the properties page in Column 9. Even though that column deals with the event model in Navigator 4.0x, these event handler approaches are fundamental, and are supported by Internet Explorer 4.0x as well. The entire event model is based on the ability to capture and process events with event handlers.

http://www.internet.com

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


Created: December 30, 1997
Revised: December 30, 1997

URL: http://www.webreference.com/js/column10/eventhandlers.html