2013-07-10 94 views
1

我現在這樣的代碼:運行「確定」一個PHP代碼,使用後確認()

<form id="form1" name="form1" method="post" action="" 
     onclick="return confirm('This is irreversible. Are you sure?');"> 
    <input type="hidden" name="act" value="run"> 
    <input id="btnDelete" name="btnDelete" type="button" value="Delete Selected"/> 
</form> 

<?php 
    if (isset($_POST['act'])) 
    { 
     echo "<script>alert(\"sup\");</script>"; 
    } 
?> 

警報是檢查是否當我按下「確定」,它將運行。目前沒有。我在我的智慧結束,特別是因爲我幾乎是一個JavaScript的菜鳥。如果有人能幫助它,將不勝感激!

+0

*旁註:*'id'和'name'在提交按鈕,您的形式是在你的情況是不必要的。 – Raptor

回答

3

給一個type="submit"你的提交按鈕,和onsubmit事件您form

<form id="form1" name="form1" method="post" action="" 
    onsubmit="return confirm('This is irreversible. Are you sure?');"> 
    <input type="hidden" name="act" value="run"> 
    <input id="btnDelete" name="btnDelete" type="submit" value="Delete selected"/> 
</form> 
+1

哦,我的上帝,解決了一切。你是一個智者!? <3 – ohhreeohh

+0

您可以將我的答案設置爲「接受答案」;)(左邊的勾號) – mquandalle