Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This function cancels an event and prevents it from bubbling up.

Parameters:

  • event – event name to cancel

Example:

In this example, we prevent the onclick event if other fields on the screen are not validated properly.

Note: We assume that validated() is a custom-built function that is available for use. We also assume that validated() returns true or false to indicate the validity of certain fields on the screen.

Code Block
javascript
javascript
var submitButton = getObj("my_button");

submitButton.onclick = function(event)

{
     if(!validated())      //if fields on the screen are not valid
     {
          preventEvent(*event*);
     }
}