Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

exit script to confirm form completion

I have a sign up form that is spread across 4 pages. They need to complete at least Step 1 and Step 4 in order for their membership to be active.

On the page for step 2 I want a script that will pop a warning window if the user tries to navigate away from the page that says something like:

"are you sure you want to navigate away from this page? If you do not complete the registration process your account will remain inactive"

and from there have 3 Options:

1. Yes, take me away
2. No, let me stay on this page to complete step 2
3. No, let me skip ahead to complete step 4

I want this to pop up if the user does anything other than hit the submit button on the form.

I've tried mucking about with some free scripts online but my knowledge of javascript is very limited.

Thanks!
0
ag1138
Asked:
ag1138
  • 3
1 Solution
 
bugadaCommented:
No you can't, you can only show a dialog with a message and Ok/Cancel buttons.
The event is not w3c compliant but is widely supported.
<script>
window.onbeforeunload(e) {
   var message = "are you sure you want to navigate away from this page? If you do not complete the registration process your account will remain inactive";
   
   e = e || window.event;
   e.returnValue = message;
   return message;
}
</script>

Open in new window

0
 
bugadaCommented:
sorry i made a typo
<html>
  <head>
  <title></title>
 
<script>
window.onbeforeunload = function(e) {
   var message = "If you do not complete the registration process your account will remain inactive";
   e = e || window.event;
   e.returnValue = message;
 
   return message;
}
</script>
 
  </head>
  <body>
  
   <input type="text" tabindex=1 onkeydown="return test()">
   <input type="text" tabindex=2 onkeydown="return test()">
   <input type="text" tabindex=4 onkeydown="return test()">
   <input type="text" tabindex=3 onkeydown="return test()">
 
  </body>
</html>

Open in new window

0
 
ag1138Author Commented:
is there a way to block that pop up from happening when the click the submit button?
0
 
bugadaCommented:
Yes just assign null to the event handler
function stopMsg() {
   window.onbeforeunload = null;
}
 
<input type="button" onclick="stopMsg();">

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now