Updated: 04/26/2017 by Computer Hope

eventIn programming, an event is an action that occurs as a result of the user or another source, such as a mouse being clicked, or a key being pressed. An event handler is a routine that is used to deal with the event, allowing a programmer to write code that will be 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 on a button within 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!');">

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 below button.

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