2015-11-14 57 views
0

我正在使用圖像提交表單。但是我無法在提交之前讓表單顯示確認對話框。添加確認框以提交圖像

我通常使用onClick()這個,但現在,因爲我用它來提交它現在爲我工作。

有沒有辦法讓它工作,以便它在提交之前顯示一個確認框?

<form style="margin-bottom: 0px;" method="post"> 
<input type="hidden" name="doc_to_delete" value="{$documents[sec1].doc_id}" /> 
<img src="../images/action_images/delete.jpg" style="height: 20px;" title="Delete Document" onclick="submit();"/> 
</form> 

回答

2

不要在提交按鈕提交

而是使用onsubmit="return confirm('Are you sure')"

這樣

<form id="form1" onsubmit="return confirm('Are you sure')" style="margin-bottom: 0px;" method="post"> 
<input type="hidden" name="doc_to_delete" value="{$documents[sec1].doc_id}" /> 
<input type="image" src="../images/action_images/delete.jpg" style="height: 20px;" title="Delete Document" /> 
</form> 
更好

不具有內聯代碼:

window.onload=function() { 
    document.getElementById("form1").onsubmit=function() { 
    return confirm('Are you sure'); 
    } 
} 
+0

它確實不檢查th e點擊時,onsubmit()。它只是立即提交。 – Marcel

+0

'任何控制檯錯誤?你是否從圖像中刪除了點擊處理程序?它應該順便說一下'' – mplungjan

+0

我沒有看到那部分內容。現在工作就像一個魅力:)謝謝 – Marcel