HTML: How to make a real onchange event in HTML (without jquery)?

Please note: I do not want to use jQuery for this (otherwise I like it)

Problem: I came in a situation where I need to execute some javascript function after the user changes the input field (for example, input type = "text"). So I said to myself: I remember the onchange event - the BUT onchange event is onchange AFTER the user leaves the field, but I need a function that should be called, for example, every time the user enters a character in this field. Wowhead shows a good example of what I'm trying to achieve this (field with a placeholder "Search by results ...")

Summary: I'm looking for a SIMPLE way to detect a REAL onchange event ( not classic HTML code ) and through this call a JS function without using jQuery ?

Thanks in advance!:)

+6
source share
4 answers

Below is an easy way to call each type of keystroke in a field.

input type = "text" onkeypress = "myFunction ()

Get an example here

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onkeypress

Enjoy ..

you can also use onkeyup and onkeydown instead of onkeypress.

+4
source

Use onkeyup instead of onchange.

+10
source

Tried onkeypress = "myFunction ()" or onkeyup = "myFunction ()"?

There are also events for onfocus and onblur to enter and exit the text field :)

+1
source

You must use the "input" event. keyup and keypress do not work if the user only changed the value with the mouse.

0
source

All Articles