Submit question on Exit page

Hi there,

I have a page with a form to database

When exiting the page, I want it to ask me whether I would like to save or dismiss changes

I have so far the following..how do I apply this so that it submits the form if ok is clicked?

Thanks

Max

<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Are you sure you want to exit? \n\n Please save changes or cancel them!");
if (agree)
      return true ;
else
      return false ;
}
// -->
</script>
</head>

<BODY onUnload="return confirmSubmit()">
<form name="company" method="POST" action="<%=MM_editAction%>">
LVL 1
MaximusMeridusAsked:
Who is Participating?
 
masirofConnect With a Mentor Commented:
formname.submit();
0
 
MaximusMeridusAuthor Commented:
How to I have a save or dismiss button on the message box?

Max
0
 
snavebelacCommented:
I dont use JavaScript for this as you cannot easily (as far as I know) modify the look and options of the dialog box.  I prefer to use a separate section of my ASP page to act as a confirmation.

            Dim conf
            conf = Trim(Request.QueryString("conf"))
            If conf <> "yes" Then
                  %>
                        <h1 style="text-align:center;">Confirm deletion</h1>
                        <div id="dialog">
                              <p>Are you sure you wish to delete this PRODUCT from the database?  This action cannot be undone !</p>
                              <div class="button" style="float:left;"><a href="manageproduct.asp?act=3&pid=<%=pid%>&conf=yes">Yes - Delete</a></div>
                              <div class="button" style="float:right;"><a href="/manageproduct.asp">No - Go back</a></div>
                        </div>
                  <%
                  Response.End
            ElseIf conf = "yes" Then
                  Con.Execute("DELETE FROM tbl_Product WHERE productID=" & pid)
                  %>
                  <meta http-equiv="refresh" content="0;URL=/admin/manageproduct.asp?msg=Product%20deleted">
                  <%
            End If


Something like that.  this can be customised to show a record or the contents of the form and then it is simpkly amatter of clicking Confirm or Discard or whatever else you want to use.

If you need extra help with implementing this, just ask

HTH

C
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.