2013-01-08 82 views
2

添加確認框如何在提交按鈕之前添加確認框?

這是我的代碼,我想給它添加一個確認框。

我有兩個submit按鈕的窗體。我需要確認框,然後發送到下一頁。我怎樣才能做到這一點? 這是確認框的代碼,我如何將它放在我的表單中?

onclick="return confirm('Are you sure?');" 

myform.jsp

<form id="form1" name="form1" method="post" action=""> 
    <p>&nbsp;</p> 
    <p align="center">Enter your choice:- 
    <label> <br /> 
    <label> 
     <input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';this.form.submit();" /> 
    </label> 
    <br /> 
    </br> 
    <label> 
     <input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';this.form.submit();" /> 
    </label> 
    <br/> 
    </div> 
</form> 

回答

5

在按鈕類試試這個

$('.class').appendTo('body') 
    .html('<div><h6>Yes or No?</h6></div>') 
    .dialog({ 
    modal: true, title: 'message', zIndex: 10000, autoOpen: true, 
    width: 'auto', resizable: false, 
    buttons: { 
     Yes: function() { 
      doFunctionForYes(); 
      $(this).dialog("close"); 
     }, 
     No: function() { 
      doFunctionForNo(); 
      $(this).dialog("close"); 
     } 
    }, 
    close: function (event, ui) { 
     $(this).remove(); 
    } 
}); 
0

試試這個

<form id="form1" name="form1" method="post" action="/your/url.xyz" onsubmit="return confirm('bla bla');"> 
+1

這裏給第二個按鈕的動作? – user1950705

0
<input type="submit" name="Submit" value="Delete" onclick='confirm(this,"delete1.jsp?flag=1&act=1")' /> 
<input type="submit" name="Submit" value="delete" onclick='confirm(this,"logi.jsp?flag=1&act=1")' /> 

function confirm(this,foo1) 
{ 
var foo = confirm('Are you sure?'); 
if (foo) {this.form.action=foo1;this.form.submit();} 
else {alert('Try Later');} 
} 
+0

其工作thnx ........ – user1950705

+0

以下代碼正在傳遞圖像和文本字段。在display.jsp中的發佈請求之後,如果enctype =「multipart/form-data」且顯示圖像,則文本字段值爲null。如果不使用enctype,則會給出正確的文本字段值,並且不會顯示圖像。我們可以在JSP中從同一頁面獲取圖像和文本嗎? – user1950705

0

下面的代碼片斷是解決方案。您需要刪除this.form.submit(),因爲按鈕是提交按鈕,默認情況下會提交。

只需將onsubmit=" return window.confirm('Are you sure?');"添加到表單並從提交按鈕中刪除this.form.submit()

<form id="form1" name="form1" method="post" action="" onsubmit=" return window.confirm('Are you sure?');"> 
         <p>&nbsp;</p> 
         <p align="center">Enter your choice:- 
          <label> <br /> 


     <label> 
      <input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';" /> 
      </label> 
           <br /> 

          </br> 
        <label> 
       <input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';" /> 
      </label> 
           <br/> 

         </div></form> 
0
See this code confirm box works in this way and one sugesstion your code need a lot pf improvement 

<html> 
<head> 
<script> 
function disp_confirm() 
{ 
var r=confirm("Press a button!") 
if (r==true) 
    { 
    alert("You pressed OK!") 
    } 
else 
    { 
    alert("You pressed Cancel!") 
    } 
} 
</script> 
</head> 
<body> 

<input type="button" onclick="disp_confirm()" value="Display a confirm box"> 

</body> 
</html> 
相關問題