Home > Articles > Programming > JavaScript

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Events and Event Handlers

If you have ever done any graphical user interface programming, you are already familiar with the concept of events. Events are actions that take place outside of your program yet might or might not directly impact your program. Many events take place within your browser that you never see and never need to worry about. But there are times when you really want to do something in your code when an event takes place.

For example, consider a Web page that provides users with an interface to change their password on some computer system. The Web page has a text box for the username and a text box for the new password as well as a button to submit the new password information. Before the username and password get submitted to some other system, you want to intercept the event that occurs when the user clicks the Submit button and verify that the password adheres to some specific password rules. A password rule might state that passwords must be greater than three characters in length but less than 15 characters. By having access to events that take place behind the scenes of the browser, you can cancel the submit action and alert the user to the problem with the password she entered.

In this section you will see the types of browser events that JavaScript will let you intercept and how to capture and take action based on those events.

  • + Share This
  • 🔖 Save To Your Account