Date: 2021jan29
Update: 2025sep11
Library: jQuery
Language: javaScript
Q. jQuery: React to a value change
A.
If you have this html:
<input type=text id=mytext>
Use this code:
$(document).ready(function() {
$('#mytext').change(function() {
console.log('changed to ' + $(this).val());
});
});
Or for a checkbox:
<input type=checkbox id=mycheck>
Use this code:
$(document).ready(function() {
$('#mycheck').clicked(function() {
const val = $(this).prop('checked');
console.log('changed to ' + val);
});
});