Given your save button info:
<input class="btn-primary" name="commit" type="submit" value="Save Material">
You can set the value of formmodified
$("input[name="commit"]").click(function() {
formmodified = 0;
});
Your check at the end shouldn’t be triggered now