?
Solved

Cancel navigation, close etc...

Posted on 2004-03-30
7
Medium Priority
?
1,772 Views
Last Modified: 2007-12-19
I have a form that is rather long to fill in and I need a way to warn the user that the data has not been submitted before he/she leaves the page.

The main key for deciding if the form has been submitted is that a checkbox has been checked.

So far, I have a script that starts like this:

<script>
   function checkleave() {
    if (document.myForm.myCheck.checked) {
     alert ("Your data was not submitted, please click on the submit button before leaving.");
     // Help needed here...
     }
  }
</script>

And in my body:

<body onunload='checkleave()'>
<form name='myForm' ...

So what I would like to do is to return the user to my page after the alert...

Now it would be nice if the form was just submitted automatically and passthrough to where-ever the user wants to go without having to return to my page after the alert but that sounds hard and my brain is very tiny and kinda full right now so I'm not sure if I can handle that.
0
Comment
Question by:bganoush
[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
  • 3
7 Comments
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 1000 total points
ID: 10714905
Did you try:

<script>
   function checkleave() {
    if (document.myForm.myCheck.checked) {
       //alert ("Your data was not submitted, please click on the submit button before leaving.");
       document.myForm.submit();
     }
  }
</script>

0
 
LVL 25

Accepted Solution

by:
devic earned 1000 total points
ID: 10714988
you need here onbeforeunload event:
=============
<body  onbeforeunload="if(document.myForm.myCheck.checked) return 'You didn\'t saved your document' ;else return">
<form name='myForm'>
<input type=checkbox  name=myCheck>
<form>
0
 

Author Comment

by:bganoush
ID: 10724349
Zvonko,

Do you know if this works in all exit cases? The only ways out of a page seem to be clicking on a link, closing the window, a script redirection and typing a URL.... are there more ways?

-- Bubba
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bganoush
ID: 10724765

Actually, I tried the submit but the problem is that it will perform the action from the form but will not redirect to the user's original URL... For instance, if the user click a link that goes to MSN.COM but the FORM has and action that goes to YAHOO.COM, then the orignal link is ignored...

Ex: (Try this, it's pretty funny.)

<HTML>
<SCRIPT LANGUAGE='Javascript'>
function checkleave() {
  if (document.myForm.myCheck.checked)
    document.myForm.submit();
}
</SCRIPT>
<BODY onunload='checkleave();'>
<FORM name='myForm' action='http://www.yahoo.com'>
<INPUT type='checkbox' name='myCheck'> I prefer Yahoo
</FORM>
<A HREF='http://www.msn.com'> Go to MSN </A>
</BODY>
</HTML>

Note that when you click on "Go to MSN" with the checkbox turned off, then it goes to MSN, no accounting for taste... But if you click on the checkbox "I prefer Yahoo" then clicking on the "Go to MSN" link will go to Yahoo but will not continue on to MSN.

In my application, my form submits via a C++ CGI and I just want the form to be submitted to the CGI and then I want to redirect to the user's original click or URL whatever was requested.

PS: devic,
ONBEFOREUNLOAD????      Never heard of it... can I get one in paisley or to match my mom's Royal Daulton?

-- Bubba
0
 
LVL 25

Expert Comment

by:devic
ID: 10724950
hehe yes,  onbeforeunload, try example above:
0
 

Author Comment

by:bganoush
ID: 10725041
Alright,

That does work... just one more thing...  Can I assume that onbeforeunload works on older versions of IE and Netscape?  My HTML manual doesn't mention it and it's only about 2 years old... (No it's not HTML for Dummies!)

-- Bubba
0
 
LVL 25

Expert Comment

by:devic
ID: 10725077
this is IE feature IE 4.0 +
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 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