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.
- 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>chevron_rightfilter_none - 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>chevron_rightfilter_none - Output:

Recommended Posts:
- JQuery | Detect a textbox content is changed or not
- How to check whether the enter key is pressed in a textbox or not using JavaScript / jQuery ?
- How to trigger HTML button after hitting enter button in textbox using JavaScript ?
- How to move button in the same line with Checkbox and Textbox using JavaScript ?
- How to detect and change the content/style of a div using jQuery ?
- How to create a simple editable canvas textbox using Fabric.js?
- How to Display Changed Browser URL Without Reloading Through alert using JavaScript ?
- Projecting Content into Components with ng-content
- Detect a device is iOS or not using JavaScript
- How to detect touch screen device using JavaScript?
- Detect the Operating System of User using JavaScript
- How to detect flash is installed or not using JavaScript ?
- How to detect the device is an Android device using JavaScript ?
- How to detect operating system on the client machine using JavaScript ?
- How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ?
- How to detect the Internet connection is offline or not using JavaScript?
- How to detect when the window size is resized using JavaScript ?
- How to detect whether a device is iOS without using Regular Expression in JavaScript?
- How to detect when cancel is clicked on file input using JavaScript ?
- How to detect network speed using JavaScript?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


