Events vs Commands

Event Handlers all work basically the same way. As long as I understand the format, I can think through the logic of getting it to run, creating new scripts for my webpages. There are about 30 Event Handlers, but here is a list of the ones that are covered in this Chapter:

My textbook calls onClick and onSubmit "commands" while the others were listed as "Event Handlers". I think the author used the wrong terms and that this list contains only Events.


My confusion about what is an Event and what is a Command, sent me researching. By understanding these terms, I hope to understand the Event Handler code better. What I learned was interesting. Events are things that have happened (past tense) and commands are an order to do work (future tense).

onEvent="JavaScript code (command)"

EVENTS are past-tense because they are something that happened already, such as a button was clicked or a mouse was rolled over. Event descriptions tell us what happened. We tend to model event-driven code around the present tense of an event, with functions like onClick or onMouseOut – but the reality is that events have already happened. Nothing further develops until that event takes place first.

COMMANDS are future-tense orders to do something. The order (or method) is performed in the future, telling the subject what to do. Commands are orders written, prior to the work being done. When a command is ordered, something needs to be around to handle it, or the work won’t get done. There may be a queue of available handlers with some means of picking which one(s) do the work. There may be only 1 command handler around that does everything. Without command handlers, there will be null errors, and the script won't work.

Back Table of Contents Next