0

I want to make a confirmation before user leaving the page if there's a incomplete registration or refresh the registration page

JQUERY CODE:

$(document).ready(function(){
$('input[name=subdomain]').keyup(subdomain_check);
$('input[name=password]').keyup(password_strenght);
$('input[name=c_password]').keyup(password_check);
$('input[name=email]').keyup(email_check);

$("#install").on('submit', function(){
return subdomain_check() && password_strenght() && password_check() && email_check();
});
window.onbeforeunload = function() {
return 'Are you sure you want to navigate away from this page?';

};

});

But the confirmation pop up in every step of the registration, even if the registration is complete! How can I prevent that from happening?

dreamweiver
  • 6,002
  • 2
  • 24
  • 39
SpencerX
  • 5,453
  • 1
  • 14
  • 21
  • Be aware that window.beforeunload is not necessarily supported by all browsers http://stackoverflow.com/questions/14645011/window-onbeforeunload-and-window-onunload-is-not-working-in-firefox-safari-o – user3358344 Mar 03 '14 at 11:57
  • Use a flag. How do you know registration is complete? Do you use Ajax? – Ram Mar 03 '14 at 11:58

1 Answers1

1

You need to put this code in js file,

/* Dirty Flag */
$(document).ready(function() {
  is_dirty = false;
  $(window).bind('beforeunload', handle_unload_event);
  setDirtyFlag("form1");// Here form1 is the ID of form
});

function setDirtyFlag(frmID){
    $('#'+frmID).find(':input').each(function(){
        $(this).change(function(){
            is_dirty = true;
        });
    });
}
HB Kautil
  • 267
  • 1
  • 6