Confirmation dialog with HTML5 button element
I have a button element like this:
<button name="command" type="submit" form="frmLandUnits" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
<span class="glyphicon glyphicon-trash" aria-hidden="true">
</span></button>
This is the part of the data entry grid for the table that is inside the form. There are other buttons on each line like Update and there is a new line with an Insert button. The problem is that when clicked, the OKform is not submitted. A google search about this showed nothing that I could find.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form name="frmLandUnits" method="POST" action="https://httpbin.org/post">
<button name="command" type="submit" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
<span class="glyphicon glyphicon-trash" aria-hidden="true">
</span></button>
</form>
Behavior is different from onclick
c input
. This is why, in my opinion, it is not a duplicate.
+3
source to share
2 answers
Just remove the attribute form
from button
.
<button name="command" type="submit" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
<span class="glyphicon glyphicon-trash" aria-hidden="true">
</span></button>
Checkout this demo
+1
source to share
<form id="frmLandUnits" method="GET" action="www.microsoft.com" onsubmit="return confirm('Do you really want to submit the form?');" >
<button name="command" type="submit" form="frmLandUnits" class="btn btn-danger"
title="Delete" value="Delete:1:352404725228987" >
<span class="glyphicon glyphicon-trash" aria-hidden="true">
</span></button>
</form>
Hope it helps.
0
source to share