Forms
See Click for the click event.
On input
Execute when a user writes something in an input
field.
The
oninput
is useful if you want to detect when the contents of atextarea
,input:text
,input:password
orinput:search
element have changed, because theonchange
event on these elements fires when the element loses focus, not immediately after the modification. source
el.oninput = myFunction()
Or
<input type="text" oninput="myFunction()">
On change
Execute when a user changes the value of an input field. This is more precise as I think it doesn’t fire if you choose the same option in the droplist as before and it only fires when you’ve click a droplist option or change focus away from a text field and not on every interaction to click or type.
onchange
occurs when the selection, the checked state or the contents of an element have changed. In some cases, it only occurs when the element loses the focus. The onchange attribute can be used with:<input>
,<select>
, and<textarea>
. source
el.onchange = myFunction()
Or
<input type="text" onchange="myFunction()">