user12828074
user12828074

Reputation:

Calling a function everytime the input text changes

I have this HTML:

<input type="text" onChange="function()">

It calls a function everytime the input value change, but to call the function you have to press the enter button or click on something that isn't the input and this is quite annoying. Is there a way to call the function everytime the text in the input change? without having to press any button or click out of the input.

Upvotes: 1

Views: 3978

Answers (2)

Hallah
Hallah

Reputation: 109

You can also use keyboard events to catch inputfield changes

    <input type="text" onkeyup="myFunc()">

Different keyboard events are

  1. Key up onkeyup
  2. Key down onkeydown
  3. Key press onkeypress

Upvotes: 1

Mamun
Mamun

Reputation: 68943

Try oninput:

Unlike oninput, the onchange event handler is not necessarily called for each alteration to an element's value.

<input type="text" oninput="myFunc()">

Please Note: You also should not use function keyword as your function name.

Upvotes: 3

Related Questions