Form Events
HTML forms generate a rich set of events that you can intercept to validate input, provide real-time feedback, and handle submission without a page reload. Mastering form events is essential for building interactive web applications.
submit
The submit event fires on the <form> element when the user submits the form. Call event.preventDefault() to prevent the default browser navigation and handle the submission with JavaScript instead.
input and change
input fires immediately on every keystroke or value change. change fires when the element loses focus after its value has changed, or for checkboxes and selects, immediately on selection. Use input for live feedback and change for final-value processing.
focus and blur
focus fires when an element gains focus; blur fires when it loses focus. Neither event bubbles, but their bubbling counterparts focusin and focusout do. Use focus/blur to show/hide labels or validate fields on departure.