Form events
Last updated
Was this helpful?
Last updated
Was this helpful?
There are a list of events that are triggered by actions from inside a HTML form. Some commonly used events are listed below:
input
- Triggered when an element gets an input.
change
- Fired the moment when the value of the element is changed.
focus
- fires the moment that the element gets focus
submit
- fires when a form is submitted.
More events can be referenced from the MDN docs here:
Event handlers can be set on HTML elements in two ways depending on your use case.
The handlers can be set in as HTML element attributes by simply prefixing on
to the event name. e.g.: submit -> onsubmit, focus -> onfocus
The below example shows how you'd do the same in JavaScript, this is suitable for scenarios where the HTML content is dynamically created.