0

I have a HTML form:

<form method="post" action="addticketupdate.php">
....

</form>

Then above the form I have:

<?php
if(isset($_POST["submit"])) {
... do stuff here
}
?>

So the submit button in my form has an id and name of "submit"

I want to make a JavaScript confirm box popup when the submit button is clicked, the statement says: If user clicks "OK" the php code excuted, else do nothing.

How can I do that?

Mat
  • 202,337
  • 40
  • 393
  • 406
charlie
  • 1,356
  • 7
  • 38
  • 76
  • possible duplicate of [Confirm before a form submit](http://stackoverflow.com/questions/6493009/confirm-before-a-form-submit) – TheEwook Oct 04 '13 at 09:36
  • @Mat It does :) It's "Elegant Slang", I got vaild result in google translate. – Yotam Oct 04 '13 at 09:49
  • @Mat it doesn't really matters, I didn't actually edited the meanning, only got the word shorter. I can't see in it any kind of foolishness. – Yotam Oct 04 '13 at 09:55

4 Answers4

1

Simply use this:

<form method="post" action="addticketupdate.php" onsubmit="return confirm('Do you want to submit the form?');" >

Option 2: (On submit button click)

$('#submit').click(function() {
    var res = confirm('Do you really want to submit the form?');
    if(!res){ 
       return false; 
    }else{ 
       //submits form 
    }
});
talha2k
  • 24,937
  • 4
  • 62
  • 81
1

You can do as,

<form method="post" action="addticketupdate.php" onsubmit="return confirm('Need to submit??');">
<!-- your other html input code -->
    <button type="submit">submit</button>
</form>
Ajith S
  • 2,907
  • 1
  • 18
  • 30
1
<script>
function validate() {
    var result = confirm("Do you want to submit!");
    return result;
}
</script>
<form name="form-name" onsubmit="return validate();"> 
Alex Tselegidis
  • 155
  • 1
  • 12
0

That should be making using dialog box instead alert popup box.
However dialog don't have full support so "Fancy Box" is the best in this case.

FancyBox

So after installizing fancy box into your website you should remove the default button they have there and change it to input type submit and add name it as "submit".

Yotam
  • 350
  • 2
  • 14