spacer

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

home / experts / javascript / column10


Explicit Event Handler Scripts

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

By now you should be familiar with the two most important event handler approaches in Internet Explorer 4.0x (HTML attributes and JavaScript properties). These approaches are important because they are also supported by Navigator 3.0x and above. That is, they are cross-browser approaches. However, Internet Explorer 4.0x also supports explicit event handler scripts.

An explicit event handler script is an ordinary script that executes only when a specific event occurs for a given object. Take a look at the following script:

<SCRIPT LANGUAGE="JavaScript" EVENT="onclick" FOR="document">
<!--

alert("Thank you for clicking the mouse button.");

// -->
</SCRIPT>

If you're running any version of Netscape Navigator, or version 3.0x of Microsoft Internet Explorer, the alert dialog box pops up immediately when you load the page. Nonetheless, if you're using Internet Explorer 4.0x, the script is executed only when a click event (EVENT="onclick") occurs for the document object (FOR="document"). Notice that the EVENT attribute gets an event handler, not an event.

When dealing with a button's event handler, the script must be placed within the form, unless the button has a unique identifier:

<FORM>
<INPUT TYPE="button" NAME="myButton" VALUE="click here">
<SCRIPT LANGUAGE="JavaScript" EVENT="onclick" FOR="myButton">
<!--

alert("Thank you for clicking the button.");

// -->
</SCRIPT>
</FORM>

For more information on event handler scoping for scripts, refer to Microsoft's documentation.

Explicit event handler scripts are pretty useless, because they aren't supported by most browsers. Browsers that do not recognize the EVENT and FOR attributes of the <SCRIPT> tag simply ignore them, so the script executes immediately when the page loads.

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle


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

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