The next event that we will study is called input
.
It occurs every time a new character is entered into the
input or textarea
. Let's look at an example. Let
us have an input:
<input id="elem">
Let's display the current contents of the input to the console every time the button is pressed on the keyboard:
let elem = document.querySelector('#elem');
elem.addEventListener('input', function() {
console.log(this.value);
});
Given an input. Let text be entered into it. As
soon as the length of the text reaches 5
,
display a message about it on the screen.
Given an input. Let it be allowed to enter 5
characters into it. There is also a paragraph. As
you enter characters into the input, write how many
more characters can be entered. When the number of
characters exceeds 5
, then output in the
paragraph how many characters the length of the
text is exceeded.