Confirmation Msg AFTER Successful Submission

Posted on 2004-11-22
Last Modified: 2010-04-06
What is the best way to display a Confirmation Msg to a user after they have successfully submitted data through a record form?

1. Using Javascript function that uses the alert("Thank you. Successful submission.") and is executed during the onClick event of a form's submit button is a client-side event meaning that it executes prior to a submission.  This is similiar to the Delete Confirmation when you prompt the user "Are you sure you want to delete this record?"  What I really need is the following:

If form submission is successful, which I guess means no error, then display to user: "Successful Submission. Thank you."
If form submission is unsuccessful, which I guess means some type of error, then display to user: "Unsuccessful Submission.  Please try again."

I usually write in ASP.  Anyone ever deal with these types of Confirmation msgs making them appear after the fact?

Thank you,
Question by:jayme9
    LVL 33

    Accepted Solution

    You are on the right track. Using javascript is the best solutuion.
    If you were delteing/updating using something like ) pseudocode)

    sql = "delete from table where id = 1"
    on error resume next
    cmd.execute sql,

    if err.Number <> 0 then
      ' Error - delete not performed.
      Response.Write "Problem in Deleting"
         Response.Write "Delete successful. " & recordsAffected & " records deleted."
    end if

    On just a form submission you cant've these error codes cos asp doesnt provide any return value.
    Instead of doing a onclick submission do a
    <form onsubmit ="retrun validate()">
    <input type = "Submit">

    the advantage of checking validn  in the onsubmit event is that if the return is false the page doesnt
    get reloaded until the error is removed.

    LVL 3

    Expert Comment

    Here's what I normally do using ASP:

    Declare a variable called errMsg
    Validate the form
       - If an item of the form is invalid, then errMsg = errMsg & "<li>Error Msg Text</li>"
    If errMsg = "" then
       - form submission is valid/process contents
       - If error is encountered while processing the contents, then errMsg = errMsg & "<li>Error Msg Text</li>"
    End If

    If errMsg = "" then   ' Success message
       Response.Write("Your information has been successfully processed!")
    Else                        ' Error message
       Response.Write("There were problems with your submission:<ul>"& errMsg &"</ul>Please try again.")
    End If

    (end pseudocode)

    Hope this helps,

    LVL 2

    Expert Comment

    You can display the message after the form has been succesfully submitted. For this you need to have 2 asp files.

    ASP File 1: The page where your form exists along with the Submit button. On click of the Submit button the page will be redirected to ASP File 2.

    ASP File 2: This file will perform the Database operations. During this server side code you can track whether your data was succesfully saved to DB or not. ANd save the response in a global Server side variable. The HTml of this file will have a jaavscript body onload function such as
    <body onload='displayMsg();'>. Now when the server side ASP code is executed then the HTml will be redered and the body onload function will be called. Access the server side variable in the JS function and dsplay the alert message accordingly.

    ASP code:
    if <error> then
    end if

    <SCRIPT LANGUAGE="JavaScript">

    function displayMsg()
        if <%=serversideVar%> ==1
            alert("Successful Submission. Thank you.");
             alert("Unsuccessful Submission.  Please try again.");

    Make sure the JS is included at the end of the same ASP page.
    SHould u have any more problems so let me know.

    Mohit Raj
    LVL 33

    Expert Comment

    Thanks modulo. Happy Holidays.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    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…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now