2017-04-02 7 views
3

Ich habe ein Knopfelement in etwa so:Bestätigungsdialog mit HTML5 Knopfelement

<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> 

Es ist ein Teil eines Dateneingaberaster in einer Tabelle, die in einer Form ist. In jeder Zeile sind andere Schaltflächen wie Aktualisieren, und es gibt eine neue Zeile mit einer Schaltfläche Einfügen. Das Problem ist, dass beim Klicken auf OK das Formular nicht gesendet wird. Eine Google-Suche ergab nichts, was ich finden konnte.

<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>

Das Verhalten anders als für onclick mit einem input. Deshalb ist das meines Erachtens kein Duplikat.

Antwort

1

Entfernen Sie einfach das form Attribut von Ihrem 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> 

Kasse this demo

+1

Das hat funktioniert. Vielen Dank :) – toddmo

+0

Viel Glück und glückliche Programmierung :) – SaidbakR

0
<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> 

Hoffe das hilft.

+0

Danke, aber ich habe keine Bestätigung auf den anderen Tasten wie Einfügen oder aktualisieren möchten. – toddmo

Verwandte Themen