2013-11-01 61 views
1

這裏我不想從提交按鈕傳遞參數。任何人都可以幫助我在提示確認消息,因此三個確認提交按鈕,其值爲確認信息

return confirm("Are you sure to Approve/Reject/Delete ?"); 

我的HTML代碼

<form name="pendingrequest" id="pendingrequest" action="formhandler.php" method="POST" onsubmit="return confirmation(this);"> 
      <table > 
       <tr> 
        <td><input type="submit" name="action" value="Approve"></td> 
        <td><input type="submit" name="action" value="Reject"></td> 
        <td><input type="submit" name="action" value="Delete"></td> 
       </tr> 
      </table> 
</form> 

例如,如果有人點擊批准,我想這一點:

return confirm("Are you sure to Approve?"); 
+0

嘗試http://stackoverflow.com/questions/9091001/how-to-show-confirmation-alert-with-three-buttons-yes-no-and-cancel -as-it –

+0

@VinodVT:問題是,在我的表單中我有3個提交按鈕。我需要提示消息,如您希望在我提交批准按鈕時批准,並且「我希望拒絕提交拒絕按鈕時」等等。 – JakeNsmith

回答

1

沒有跨瀏覽器解決方案如果您使用onsubmit

要做到這一點的唯一方法是綁定e發泄按鈕,而不是提交表單:

<!DOCTYPE html> 
<html> 
<head> 
    <script> 
    function init() 
    { 
    document.getElementById("pendingrequest").onsubmit = function(e) 
    { 
    console.log(e.target.value); 
    console.info(e.srcElement); 
    return false; 
    } 

    var submits = document.getElementsByClassName("submit-test"); 
    for(var i=0;i<submits.length;i++) 
    { 
    submits[i].onclick = function(e){ 
     var value = this.value; 
     return confirm("Are you sure to "+value+" ?"); 
    } 
    } 
    } 
    </script> 
</head> 
<body onload="init()"> 

    <form name="pendingrequest" id="pendingrequest" action="" method="POST" > 
    <table > 
    <tr> 
    <td><input class="submit-test" type="submit" name="action" value="Reject"></td> 
    <td><input class="submit-test" type="submit" name="action" value="Approve"></td> 
    <td><input class="submit-test" type="submit" name="action" value="Delete"></td> 
    </tr> 
    </table> 
    </form> 
</body> 
</html>