We don’t need to write event handlers in those special script tags. We can use event handlers inline to HTML tags. Let us see one simple example for clear understanding.
In this example, we have used onclick event handler. This event handler will pop up a message “Submitted successfully” whenever the user clicks on a button.
Download: Click here to see the output of this program in your browser. Right-click and select Save Link as to download the file.
Note: We can add more than one statement in inline event handlers also. For example, in above example, we have the user only one alert statement with the semicolon, so if we have to add more statement just write them after that semicolon.
Following is the list of all event handlers available in JavaScrit.
|Event Handler||Used In|
|onBlur||select, text, text area|
|onChange||select, text, textarea|
|onClick||button, checkbox, radio, link, reset, submit, area|
|onFocus||select, text, testarea|