How to detect If textbox content has changed using JavaScript ?
The task is to detect the changes in the textbox content with JavaScript. There are two approaches that are discussed below.
Approach 1: We will use the onchange event in the input element and call a function to see the effect.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
- Example:
<!DOCTYPE html><html><head><title>Detect If Textbox content haschanged using pure JavaScript</title></head><bodystyle="text-align:center;"><h1style="color:green;">GeeksforGeeks</h1><p>Change the text of input textand click outside of it to see.</p><inputid="input"name="input"onchange="GFG_Fun()"/><br><br><script>function GFG_Fun() {alert('Changed');}</script></body></html> - Output:

Approach 2: There are few other events that can be used to detect the change in content of textbox. Use any or all of them onchange event, onpropertychange event, onkeyup event, onpaste event and oninput event in the input element and call a function to see the effect.
- Example:
<!DOCTYPE html><html><head><title>Detect If Textbox content haschanged using pure JavaScript</title></head><bodystyle="text-align:center;"><h1style="color:green;">GeeksforGeeks</h1><p>Change the text of input text andclick outside of it to see.</p><inputid="input"name="input"onchangeonpropertychangeonkeyuponpasteoninput="GFG_Fun()"/><br><br><script>function GFG_Fun() {alert('Changed');}</script></body></html> - Output:



