The Internet Explorer Event Model: Event Processing Functions - Doc JavaScript | WebReference

The Internet Explorer Event Model: Event Processing Functions - Doc JavaScript


Event Processing Functions

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.

https://www.internet.com


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

URL: https://www.webreference.com/js/column10/functions.html