Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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

Parameters:

  • event – reference to the event to cancel

Example:

The following can be used on the onkeydown event to restrict which keys can be pressed. 

function gradeKeys(event, element) {
  var key = event.keyCode;
  switch (key) {
    case 65: // allow A
    case 66: // allow B
    case 67: // allow C
    case 68: // allow D
    case 70: // allow F
    case 8:  // allow backspace
    case 46: // allow delete
    case 37: // allow left arrow
    case 39: // allow right arrow
    case 40: // allow down arrow
    case 38: // allow up arrow
    case 13: // allow enter
      break;
    default: // disallow all other keys
      preventEvent(event);
  } 
}
  • No labels