Languages

JavaScript - how can I set ontype event on input text element?

5 points
Asked by:
Vanessa-Drake
718

After checking MDN Documentation I have noticed there is no ontype event for <input type="text"> element.

I don't want to use onchange event.

Is there some way how to handle event always on text change?

 

1 answer
6 points
Answered by:
Vanessa-Drake
718

You should use oninput event.

e.g.

// ONLINE-RUNNER:browser;

<input type="text" oninput="console.log(this.value)" />

 

OR:

// ONLINE-RUNNER:browser;

<input id="element" type="text" />
<script>
  
  var element = document.querySelector('#element');
  
  element.addEventListener('input', function() {
      console.log(element.value);
  });
  
</script>

 

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join