...

View Full Version : How to create popup confirmation after submit?



stringer
03-15-2004, 04:25 PM
I wish to open a new window to confirm that data has been submitted from a form.

I am using a 'submit' button with form method=post and action="mailto:xyz"

At present, 'submitting' the form results in a popup window, which is presumably generated by Windows XP or Outlook, warning that an e mail will be sent and asking for confirmation. After clicking Ok, the data is submitted but the form still remains on the screen.

I would like a script to perform actions in the following order, after the automatic e mail warning popup is closed by the user:

1 Open another window 'thanks.html' which confirms that the form data has been sent. This page would have a 'close this window' button.
2 After the thanks window has been closed by the user, also close the form window and return to the calling page.

Not being a programmer, I am a 'cut and paste' script user but can't find anything suitable. I would be most grateful if someone could provide a suitable script.

Willy Duitt
03-15-2004, 05:43 PM
You can look here (http://www.webxpertz.net/faqs/jsfaq/popup.php#form) for examples of what you are wanting to do.

.....Willy

stringer
03-15-2004, 08:21 PM
Thanks Willy. That link is useful for the basic function.

However, the example given does not close the window of the original data input form, which is what I want to do. Also, where in the script would I add the submit function to send the data by e mail?

The actions I need to perform are:

submit the data
open the popup confirmation window
close the confirmation window (when user clicks button) and simultaneously (if possible) close the form window

Willy Duitt
03-15-2004, 09:27 PM
Break your task down into small steps.
First do what you can and then post a link or the code and someone will try to point you in the right direction for each step.

I'm more than happy to help but I'm not going to code a main page to pop the form window, the form confirmation window and the form thanks window just to show you how to close the window. Which BTW would be something like:

onload="javascript:opener.close()"

Help us help you by providing something to work with.
Even if it is just your form page. ;)

.....Willy

stringer
03-16-2004, 08:20 AM
Apologies! The following is the code for a window 'popup test.html' that does almost everything I want, except that Windows asks to confirm closing the 'popup test' window before the 'thanks.html' popup appears. It would be tidier if 'popup test' could be closed after 'thanks.html' is closed. I have tried putting the window.close() statement after the window.open(), but it then closes the current window (thanks.html) rather than the original one.

<html>
<head>
<script type="text/javascript">
//<![CDATA[
function popupform(f) {
var url = "thanks.html"
var width = 300;
var height = 200;
var screenX = (screen.width/2 - width/2);
var screenY = (screen.height/2 - height/2);
var features= "width=" + width + ",height=" + height;
features += ",screenX=" + screenX + ",left=" + screenX;
features += ",screenY=" + screenY +",top=" + screenY+", scrollbars=1";
f.submit();
window.close('popup test.html')
var mywin=window.open(url, "popup", features);
mywin.focus();
}
//]]>
</script>
</head>
<body>

<form method="post" action="mailto:xyz@abc.co.uk" >
<input type="text" name="formitem1" value="value1">
<input type="text" name="formitem2" value="value2">
<input type="button" value="Click" onclick="popupform(this.form)" >
</form>
</body>
</html>


</body>

</html>
before before

Willy Duitt
03-16-2004, 01:02 PM
Windows asking to confirm closing the window is a security issue. Although there are hacks to close the window without a confirmation, it is unadvised to use these because it will completely close an AOL browser.

To properly avoid the confirmation alert, you will need to open the form window from another window just as you are the thanks window. (that's what a meant about the main page) in my previous post.

Try placing your form codes in a popup which is fired from another page. Thereafter you can open and close all of the windows you want. ;)

.....Willy

Willy Duitt
03-16-2004, 01:09 PM
BTW: Instead of using all of these popups. Why not simply submit the form from your page and use document.replace('thanks.htm') to redirect to the thank you page?

The replace() method will overwrite the form page in the browser history and the user will not be able to return to it thru their back button.

.....Willy

stringer
03-16-2004, 08:16 PM
Thanks again Willy. I don't want to prolong this unnecessarily, so I'll make this my last question.

I tried document.replace but it produces an error. As document.write works, I can only assume it is something to do with the version of html (3.2).

I have stuck to the original plan of generating a popup acknowledgement. The code for the function is below. It works satisfactorily except that if the user clicks cancel in the 'send e mail' popup generated by submit(), it still produces the thanks.html window as if the form had been sent. How can I check whether the submit actually took place?

function popupform(f) {
var url = "thanks.html"
var width = 300;
var height = 200;
var screenX = (screen.width/2 - width/2);
var screenY = (screen.height/2 - height/2);
var features= "width=" + width + ",height=" + height;
features += ",screenX=" + screenX + ",left=" + screenX;
features += ",screenY=" + screenY +",top=" + screenY+", scrollbars=1";
f.submit();
window.close('prescription form.html');
var mywin=window.open(url, "popup", features);
mywin.focus();
}

Willy Duitt
03-16-2004, 08:24 PM
Don't worry about how many questions you ask. ;)
It's all good as long as you are striving to learn. :thumbsup:

But, you misunderstood my suggestion.
And I meant to say location.replace() :o

Here is an example.

<html><body>
<form method="post" action="mailto:xyz@abc.co.uk"
onsubmit="return location.replace('http://google.com')">
<input type="text" name="formitem1" value="value1">
<input type="text" name="formitem2" value="value2">
<input type="submit" value="Submit">
</form>
</body>
</html>

.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum