PDA

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



topdog9926
03-13-2007, 10:58 PM
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.

thetestingsite
03-14-2007, 03:42 AM
are you talking about something like this (not valid HTML, I know):



<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.

codeexploiter
03-14-2007, 05:01 AM
Here is another example in which the form has a submit button rather than a normal command button



<!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>

dezhkam
04-22-2008, 07:48 PM
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

codeexploiter
04-23-2008, 04:20 AM
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?