Search code examples
htmlformsconfirm

how to do confirmation in a form before submit


I have this code

<form action="UMS_delete.php" method="post" onSubmit="return confirm("Are You Sure?");">
<td>
<input type="hidden" value="'.$row['username'].'" name="username">
<input type="submit" value="Delete">
</td>
</form>

I know it's very simple but it doesn't work and I don't know why

I have also tried the onclick event on the submit button

but it always go to the action page

can anybody please help?


Solution

  • I believe it's the use of double quotes in the confirm. It breaks the HTML syntax.

    Do this instead: onSubmit="return confirm('Are You Sure?');"

    This should work, I've done this many many times.