Event

Updated: 04/26/2017 by Computer Hope
Tablet with app icons floating out of the screen.

In programming, an event is an outcome that occurs due to a user's action or another source, such as a mouse click. An event handler is a routine that deals with the event, allowing a programmer to write code that is executed when the event occurs.

Other common event examples

  • A web browser completely loading a web page.
  • A file being created or modified on a filesystem.
  • A hardware sensor such as a webcam or microphone receiving sensory input.
  • The arrival of incoming network traffic.
  • The occurrence of an error at the program or system level.

Events on the Web

Another example of an event is a user clicking a button on a web page. This action creates what is known as a "click" event. JavaScript could then be used to program a reaction to the event, for instance, you could use the onclick event handler shown in the following box:

<form action="#" method="post">
<input type="button" value="Click for a Message" onclick="window.alert('Hello!');">
</form>

The code reacts to a click event on the button, sending the "Hello" message the viewer. To see this in action, be sure JavaScript is enabled in your browser and click the button below.

Browser, Error, Event listener, Filesystem, Network, Programming terms, Web page