Solved

exit script to confirm form completion

Posted on 2009-05-07
4
181 Views
Last Modified: 2012-05-06
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
Comment
Question by:ag1138
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 10

Expert Comment

by:bugada
ID: 24326884
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
 
LVL 10

Accepted Solution

by:
bugada earned 125 total points
ID: 24326997
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
 

Author Comment

by:ag1138
ID: 24327600
is there a way to block that pop up from happening when the click the submit button?
0
 
LVL 10

Expert Comment

by:bugada
ID: 24327653
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question