How to useonchange event in Javascript
We will use the onchange event in the input element and call a function to see the effect.
Example: In this example, we are using the above-explained approach.
html
<!DOCTYPE html> < html > < head > < title > Detect If Textbox content has changed using pure JavaScript </ title > </ head > < body style = "text-align:center;" > < h1 style = "color:green;" > w3wiki </ h1 > < p > Change the text of input text and click outside of it to see. </ p > < input id = "input" name = "input" onchange = "GFG_Fun()" /> < br > < br > < script > function GFG_Fun() { alert('Changed'); } </ script > </ body > </ html > |
Output:
How to detect If textbox content has changed using JavaScript ?
The task is to detect the changes in the textbox content with JavaScript. Whenever a user writes or types something in the input text box we have to detect that event by the use of some methods present in JavaScript.
There are some common approaches that are discussed below:
Table of Content
- Using onchange event
- Using onpropertychange event
- Using addEventListener() method