0

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?

Till Helge
  • 9,253
  • 2
  • 40
  • 56
user1978536
  • 95
  • 1
  • 3
  • 5
  • possible duplicate of [JavaScript Form Submit - Confirm or Cancel Submission](http://stackoverflow.com/questions/6515502/javascript-form-submit-confirm-or-cancel-submission) – Wesley Murch Jan 14 '13 at 21:29

4 Answers4

1
if(!confirm("Are you sure you want to submit this?"))
{
    return false;//do not submit
}
//go ahead and submit
Justin Bicknell
  • 4,804
  • 18
  • 26
0

Yes it is. You can define a onSubmit handler and if it return false, the submit is aborted.

http://www.javascripter.net/faq/confirm.htm

Fabian Blechschmidt
  • 4,113
  • 22
  • 39
0

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.

Mitchell M
  • 475
  • 1
  • 7
  • 15
0

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

mica
  • 500
  • 3
  • 13