I have a simple form built. A drop-down menu, a text field, and a submit button.
When the submit button is pressed, it posts the item selected in the dropdown and the text inputed in the text field.
I want to add a confirmation pop using JavaScript/jQuery. When they press "submit" a pop-up will appear that says "Are you sure you want to submit this?"
If the user says "OK", it continues with the POST action, and calls the PHP action script.
Is this possible, if so, how?
-
possible duplicate of JavaScript Form Submit - Confirm or Cancel SubmissionNo Results Found– No Results Found2013年01月14日 21:29:52 +00:00Commented Jan 14, 2013 at 21:29
4 Answers 4
if(!confirm("Are you sure you want to submit this?"))
{
return false;//do not submit
}
//go ahead and submit
Comments
Yes it is. You can define a onSubmit handler and if it return false, the submit is aborted.
Comments
There's a good example over at Tizag. This can be adapted for any confirmation. This can also be done with jQuery if you want to, but it's just as easy with the native javascript functions.
Comments
Developped @justin answer
// in domReady
$('#formID').submit(confirmSubmit);
function confirmSubmit(e){
if(!confirm("Are you sure you want to submit this?")){
return false;//do not submit
}
//go ahead and submit
}
take a look at the jQuery submit event documentation