Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1062 How can I create my own confirmation window to confirm a form submission?

You are here: irt.org | FAQ | JavaScript | Form | 7.3 | Q1062 [ previous next ]

1) Cancel the original form submission:

<SCRIPT LANGUAGE="JavaScript"><!--
var windowHandle;
function myConfirm() {
    windowHandle = window.open('confirm.htm','windowName','width=600,height=320');
    if (!windowHandle.opener)
        windowHandle.opener = self;
    return false;
}
//--></SCRIPT>

<FORM NAME="myForm" onSubmit="return myConfirm()">
<INPUT TYPE="submit">
</FORM>

2) Do not use the onSubmit event handler:

<SCRIPT LANGUAGE="JavaScript"><!--
var windowHandle;
function myConfirm() {
    windowHandle = window.open('confirm.htm','windowName','width=600,height=320');
    if (!windowHandle.opener)
        windowHandle.opener = self;
    return false;
}
//--></SCRIPT>

<FORM NAME="myForm">
<INPUT TYPE="button" VALUE="Submit" onClick="myConfirm()">
</FORM>

and in both instances in confirm.htm:

<FORM>
<INPUT TYPE="button" VALUE="Okay" onClick="opener.document.myForm.submit();self.close()">
<INPUT TYPE="button" VALUE="Cancel" onClick="self.close()">
</FORM>

©2018 Martin Webb