Successfully added
Website Feature Development
by Patrik
Detect Input Changes
To detect if the text in an input field has changed we can compare the actual value with the default value.
The following script will execute the change function whenever the user presses a key. It will then compare the value
with the defaultValue
.
<input id="elementTitle" placeholder="Title" onkeyup="change();" />
function change() {
var title = document.getElementById('title');
if (title.value === title.defaultValue) {
alert('same');
} else {
alert('different');
}
}
A simplified approach if only one input needs to be checked could be:
<input value='myDefault' onchange='if (this.value!=this.defaultValue) alert("Changed")'>
Further resources
Snippset
Referenced in:
Comments