jQuery: How to detect a textbox's content has changed using jQuery
jQuery Practical exercise Part - I : Exercise-28
How to detect a textbox's content has changed using jQuery?
Sample Solution:
HTML Code :
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>How to detect a textbox's content has changed using jQuery</title>
</head>
<body>
<form action="demo_form.asp">
First name: <input type="text" id="name1" name="fname"><br>
Last name: <input type="text" id="name2" name="lname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
JavaScript Code:
$('#name1').on('input', function() {
console.log('New First name added');
});
See the Pen jquery-practical-exercise-28 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Convert a jQuery object into a string.
Next: Remove a specific value from an array using jQuery.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics