Handling Events Using Form Elements

So far, all the functions in this chapter have been triggered by a visitor clicking a link or button.

Each type of form element has its own list of triggering events. As demonstrated in Figure 7-22, button elements can use onClick to call a function when someone clicks the button. However, not all form elements take onClick. Table 7-1 shows you some of the events that different form elements handle. You'll find a complete list in Appendix C.

Table 7-1. Some Events That Different Form Elements Can Handle

Form Element

Event

What Triggers the Event

Button

onClick

Self-explanatory

Checkbox

onClick

Self-explanatory

Radio button

onClick

Self-explanatory

Text field

onChange

Change the contents of the text field and then click out of ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.