Results 1 to 5 of 5

Thread: How do I make a confirmation pop-up appear after clicking submit button?

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I make a confirmation pop-up appear after clicking submit button?

    Hello,

    Some one has asked this before but I didn't get the answer I seek from the replies.

    When someone clicks the submit button on a form on my website, how do I make a pop-up window (java or web browser) appear confirming that their request has been received?

    Please consider that I am very html challenged.

    Thank you.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    are you talking about something like this (not valid HTML, I know):

    Code:
    <html>
     <head>
       <script type="text/javascript">
    
            function confSubmit(form) {
                if (confirm("Are you sure you want to submit the form?")) {
                    form.submit();
                }
    
                else {
                   alert("You decided to not submit the form!");
                }
            }
       </script>
     </head>
    <body>
    
    <form action="somefile.php" method="POST">
    <!--Put form elements here-->
    
    <input type="button" onClick="confSubmit(this.form);" value="Submit Form">
    </form>
    
    </body>
    </html>
    Note: the above is just an example to see if that is what you are talking about. Copy and paste the above code into an html file to see the results.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Here is another example in which the form has a submit button rather than a normal command button

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    function executeOnSubmit()
    {
    	var status = checkField();
    	
    	if(status == false)
    	{
    		alert('Please enter some data in the text field');
    		return false;
    	}
    
    	var res = confirm("Do you really wish to submit the form contents?");
    	
    	if(res)
    		return true;
    	else
    		return false;
    }
    
    function checkField()
    {
    	//Please note that I haven't done any detailed form validation in this case.
    	
    	var elemValue = document.getElementById("name").value;
    	if(elemValue == "")
    		return false;
    	else
    		return true;
    }
    </script>
    </head>
    
    <body>
    <form action="test.php" method="post" onsubmit="return executeOnSubmit();">
    <label>Name</label><input type="text" name="name" size="20" id="name" />
    <br>
    <input type="submit" name="submit" value="submit" />
    </form>
    </body>
    </html>

  4. #4
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This can be done as easy as this: I did it with a anchor rather than button:

    <a href="delete.php" onclick="return confirm('Are you sure you want to delete this item?');">delete</a>

    Cheers,

    Nima Dezhkam

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by dezhkam View Post
    This can be done as easy as this: I did it with a anchor rather than button:

    <a href="delete.php" onclick="return confirm('Are you sure you want to delete this item?');">delete</a>

    Cheers,

    Nima Dezhkam
    There is some misinterpretation of the main question here. The question was someone wants to submit a form but before the actual form submission occur he needs to make sure that whether the user wants to do the submission or not.

    The code you've provided does not submit a form as the click on the link will open a confirm box and will be redirected to the file or sit idle based on the confirm button click.

    Suppose think that the file that contains the link you've provided an HTML form a submit/normal button and the user wish to submit the form. How could one can achieve this with your code?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •