spacer

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

home / experts / javascript / column10


Event Processing Functions

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

In Internet Explorer 4.0x, like all other JavaScript-enabled browsers, you can cancel an event by returning false. Here's an example that cancels a form submission:

<FORM NAME="myForm" ACTION="...">
.
.
.
<INPUT TYPE="submit" VALUE="submit">
</FORM>

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

function cancelSubmit() {
  return false; // cancel event
}

document.myForm.onsubmit = cancelSubmit;

// -->
</SCRIPT>

For more information on this method, refer to Column 9's "Event Processing Functions" page. Note that the "e" parameter in these examples doesn't play a role in Internet Explorer 4.0x.

In Internet Explorer 4.0x, every object has a event.returnValue property. This read-write property can be either true or false. Setting it to false cancels the default action of the source element of the event. The value of this property takes precedence over values returned by the function, such as through a return statement. Here's the previous example using the returnValue property to cancel the form submission:

<FORM NAME="myForm" ACTION="...">
.
.
.
<INPUT TYPE="submit" VALUE="submit">
</FORM>

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

function cancelSubmit() {
  window.event.returnValue = false; // cancel event
}

document.myForm.onsubmit = cancelSubmit;

// -->
</SCRIPT>

We'll describe the event object later in the column, so don't worry about it now.

If you're not familiar with other scripting languages, this property may seem redundant. The returnValue property is essential for languages that don't support return values. However, JavaScript does support return values, so you should stick with the return statement. Also note that Navigator doesn't support this property.

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/functions.html