How to detect the value of input field after a keydown event in the input field with JavaScript?

Sometimes, we want to detect the value of input field after a keydown event in the input field with JavaScript.

In this article, we’ll look at how to detect the value of input field after a keydown event in the input field with JavaScript.

How to detect the value of input field after a keydown event in the input field with JavaScript?

To detect the value of input field after a keydown event in the input field with JavaScript, we can use the value property.

For instance, we write:

<input>

to add an input.

Then we write:

const input = document.querySelector('input')
input.onkeydown = (e) => {
  console.log(e.target.value)
}

to select the input with querySelector.

And then we set the input.onkeydown property to a function that logs the input value, which is stored in e.target.value.

Conclusion

To detect the value of input field after a keydown event in the input field with JavaScript, we can use the value property.