A form event is fired when a form control receive or loses focus or when the user modify a form control value such as by typing text in a text input, select any option in a select box etc. Here're some most important form events and their event handler.
The Focus Event (onfocus)
This event occurs when an element gets focused on a web page. The onfocus event handler is used to handle this event. The following example will highlight the background of text input in green color when it receives the focus.
<select onchange="alert('You have changed the selection!');">
<p><strong>Note:</strong> Select any option in select box to see how it works.</p>
Note: Select any option in select box to see how it works.
The Submit Event (onsubmit)
The submit event occurs when the submit button is clicked. The onsubmit event handler is used to handle this event.
The following example will show you an alert message while submitting the form to the server.