jquery warn if leaving page without clicking the save button
$('#form').data('serialize',$('#form').serialize()); // On load save form current state
$(window).bind('beforeunload', function(e){
if($('#form').serialize()!=$('#form').data('serialize'))return true;
else e=null; // i.e; if form state change show box not.
});
You can Google JQuery Form Serialize function, this will collect all form inputs and save it in array. I guess this explain is enough :)
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