troulbe adding success flag to onbeforeunload

Posted by Dirty Bird Design on Stack Overflow See other posts from Stack Overflow or by Dirty Bird Design
Published on 2010-06-16T17:03:46Z Indexed on 2010/06/16 17:12 UTC
Read the original article Hit count: 202

Filed under:
|

having issues with onbeforeunload. I have a long form broken into segments via a jquery wizard plug in. I need to pop a confirm dialog if you hit back, refresh, close etc on any step but need it to NOT POP the confirm dialog on click of the submit button. had it working, or at least I thought, it doesn't now.

<script type="text/javascript">
var okToSubmit = false;
window.onbeforeunload = function() {
document.getElementById('Register').onclick = function() { okToSubmit = true; };
if(!okToSubmit) return "Using the browsers back button will cause you to lose all     form data. Please use the Next and Back buttons on the form"; 
};
</script>

'Register' is the submit button ID. Please help!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about onbeforeunload