var form = document.querySelector('form');
function detectChange() {
var inputs = form.querySelectorAll('input');
for (var input of inputs) {
if (input.value) {
return true;
}
}
}
form.querySelector('button').addEventListener('click', function() {
if (detectChange() && confirm('Are you sure you want to reset?')) {
form.reset();
}
});
You should usually avoid including reset buttons in your forms. They’re rarely useful, and are instead more likely to frustrate users who click them by mistake (often while trying to click the submit button).
When one field contains invalid text in a number field, and the other field has a number, the confirm then correctly occurs.
If you ever intend for something other than numbers to be in the form field, then don’t make it a number field. Values that aren’t valid numbers aren’t allowed to be set in number fields, and are seen as being empty.