Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Events with HTML Form Controls | DOM Event Handling and Forms
HTML & JavaScript Interactivity for Beginners
course content

Course Content

HTML & JavaScript Interactivity for Beginners

HTML & JavaScript Interactivity for Beginners

1. DOM and HTML Manipulation
2. DOM Event Handling and Forms
3. JavaScript HTML5 APIs
4. Beginner Projects with HTML + JavaScript

bookEvents with HTML Form Controls

So far, you've learned how to handle DOM events using event attributes and adding event listeners to HTML elements. In this chapter, you'll learn events on form elements like text input, checkboxes, select boxes, and radio buttons. HTML forms allow users to interact with a web application; thus, events on the forms form an integral part.

Onfocus Event

The onfocus event is fired when you set your mouse on HTML form elements such as <input> and <select> elements.

html

index

css

index

js

index

copy

Onblur Event

Next is the onblur event, which is the opposite of the onfocus event, and it is triggered when an element loses its focus. Let's display the id of the input element in the <p> 'demo' tag in the above example when it loses its focus.

html

index

css

index

js

index

copy

onchange Event

The onchange event occurs when you change a value of an element. It is used with HTML form elements such as <input>, <select>, and <textarea>. Let's try it with the <select> option.

html

index

css

index

js

index

copy

oninput Event

Unlike the onchange event, the oninput triggers when you try to change a value in a <textbox> or <textarea>. Let's find out how it types the value of the <textbox> in the 'demo' paragraph tag as soon as you start typing the text.

html

index

css

index

js

index

copy

Oncontextmenu Event

The oncontextmenu triggers when you right-click your mouse on a form element. You can use this event in other controls in any HTML element, not just on forms. Let's find out what happens when you right-click an <input> element where you're supposed to enter your name.

html

index

css

index

js

index

copy

onsubmit Event

The onsubmit event is triggered when the user submits the form. This function is handy when you fill in all the form fields and submit the form for client-side validation, which you'll discover in the next chapter.

html

index

css

index

js

index

copy
1. Which of the following events is triggered when a user leaves a form element?
2. Which of the below methods is triggered as soon as a user changes a Textarea element?
Which of the following events is triggered when a user leaves a form element?

Which of the following events is triggered when a user leaves a form element?

Select the correct answer

Which of the below methods is triggered as soon as a user changes a Textarea element?

Which of the below methods is triggered as soon as a user changes a Textarea element?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 3
some-alt