Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-13-2007, 10:58 PM
topdog9926 topdog9926 is offline
Junior Coders
 
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.
Reply With Quote
  #2  
Old 03-14-2007, 03:42 AM
thetestingsite's Avatar
thetestingsite thetestingsite is offline
The Guy That Moderates
 
Join Date: Sep 2006
Location: St. George, UT
Posts: 2,795
Thanks: 3
Thanked 156 Times in 154 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
The Testing Site | Atomic Yeti
Reply With Quote
  #3  
Old 03-14-2007, 05:01 AM
codeexploiter's Avatar
codeexploiter codeexploiter is offline
Elite Coders
 
Join Date: Sep 2005
Location: India
Posts: 1,620
Thanks: 6
Thanked 104 Times in 104 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>
__________________
-Codex
http://jpvalappil.wordpress.com/
Reply With Quote
  #4  
Old 04-22-2008, 07:48 PM
dezhkam dezhkam is offline
New Comer (less than 5 posts)
 
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
Reply With Quote
  #5  
Old 04-23-2008, 04:20 AM
codeexploiter's Avatar
codeexploiter codeexploiter is offline
Elite Coders
 
Join Date: Sep 2005
Location: India
Posts: 1,620
Thanks: 6
Thanked 104 Times in 104 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?
__________________
-Codex
http://jpvalappil.wordpress.com/
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:26 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.