[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Cancel navigation, close etc...

Posted on 2004-03-30
7
Medium Priority
?
1,778 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

650 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