I would say that the combination of the two approaches proposed by adeneo and ACEfanatic02., With a twist:
$("input:visible").change(function() { var currID = $(this).prop("id"); var initialValContainer = $("#Initial" + currID); if (initialValContainer.length > 0) { var currVal = $.trim($(this).val()); var initialVal = $.trim(initialValContainer.val()); if (currVal === initialVal) { $(this).addClass("changed"); } else { $(this).removeClass("changed"); } } });
At this point, when you are ready to check whether you want to save, you can use the following code to find out if this is necessary:
if ($(".changed").length > 0) { **prompt to save** }
Thus, the code will only ask if at least one of the inputs has been marked as changed. This approach will also allow you to enter "untag", which the user returns to their original value, as well as "reset" all inputs if you need with $(".changed").removeClass("changed") (for example, if you save new values without reloading the page).
source share