Hi everyone, this is my first post here! As I wrote in the title of the post, I need my JavaScript code to do this action: a confirmation prompt must appear when users leave a page with a form containing unsaved editings, but the prompt shouldn't appear if users submit this form clicking on some buttons.
This is the code I tried:
Code:
var clicked;
$(document).ready(function() {
$(".button").click(function(){
clicked = 1;
});
if (form_is_modified(document.forms[1])) {
get();
}
else {
}
function get(){
if(clicked == 1) {
} else {
confirmUnload(true);
}
}
function confirmUnload(on) {
var message = "You have unsaved data. Are you sure to leave the page?";
window.onbeforeunload = (on) ? function() { return message; } : null;
}
I do not post the function "form_is_modified" through which I check if the form contains unsaved editings, because is working well. Everyone has suggestions?
Thanks so much, bye!