簡體   English   中英

JavaScript表單即使變量為false也會提交

[英]Javascript form submits even when variable is false

因此,我試圖讓用戶在提交表單之前確認他們的操作,因此我嘗試使用確認框。 當我測試它時,即使在確認框中按“取消”時,也會提交表單。 因此,我嘗試僅將變量'c'設置為false,然后說如果c == true,則提交表單,並且表單仍提交! 我不明白為什么會這樣。 任何幫助,將不勝感激!

因此,為了清楚起見,該表單仍以以下代碼提交:

<button onclick=\"extendBids('$studentID')\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   //var c=confirm("Are you sure? This action cannot be undone.");
    var c=false;
    if (c==true){
      document.forms["addToRush"].submit();
   }
}

嘗試這個 -

<button onclick=\"extendBids('$studentID');\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   if(confirm("Are you sure? This action cannot be undone.")){
      document.forms["addToRush"].submit();
      return true;
   }
   return false;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM