Search code examples
javascripteventsinputonblur

how to instantly print result when enter a number in text field


Like i have a text field to input only numbers and i want to make a multiplier. Like if i write 1 it instantly multiplies the number(1) to say 2 and if continue writing the number like i already wrote 1 and continue to add 2 in that to make it 12 and again it instantly multplies 12 with 2 and shows the result.

So i wanna know exactly how to show a result when i input any number in text field. I can show result by using onBlur or by clicking a button but i want to print the message as soon as i press the key on the keyboard..

I havent tried anything so plz help me with this


Solution

  • You can use onkeyup event like this

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