JSFiddle - React, Tailwind, and code Playground
HTML
This is quick, but it won't take care of `ctrl+z` or `cmd+z` and it will give you a false positive when pressing `shift`, `ctrl` or the `tab` key:
<br /><br />
<form id="my-form">
<input type="text" />
<br />
<select>
<option></option>
<option>0</option>
<option>1</option>
<option>2</option>
</select>
<br />
<textarea rows="5"></textarea>
<input type="checkbox" />
<input type="radio" name="radio" />
<input type="radio" name="radio" />
</form>
<button id="change-monitor">Ready for testing. Change an input.</button>
CSS
body,
button {
font-family: 'Arial';
font-size: 16px;
}
form {
width: 50%;
padding: 15px;
background-color: #dddddd;
margin-bottom: 15px;
}
form * {
width: 100%;
margin-bottom: 15px;
}
JavaScript
$(document).ready(function() { // or when your form is populated after an ajax call
$('#my-form').find(':input').each(function(index, value) {
$(this).data('val', $(this).val());
});
})
$('#my-form').on('change paste', ':input', function(e) {
$('#change-monitor').html('Form has changed. Click to reset.');
});
$('#my-form').on('keyup', ':input', function(e) {
if ($(this).val() != $(this).data('val')) {
$('#change-monitor').html('Form has changed. Click to reset.');
$(this).data('val', $(this).val());
}
});
$(document).on('click', '#change-monitor', function() {
$('#change-monitor').html('Ready for testing. Change an input.');
})