Javascript Confirm Form Submission

來源:互聯網
上載者:User
Javascript Confirm Form Submission
By Nannette Thacker - 11/17/2000 Updated: 2/15/2001

Oft times you may wish to have the user confirm, before they process a form's action. For instance, clicking the button may activate a deletion process which you wish to have the user confirm before proceeding.

This code allows your users to confirm whether they wish to proceed when processing a form with serious consequences, such as DELETE.

You may also use the confirmSubmit() function for confirming whether to proceed with a hyperlink and you may assign it to a single button on a form. For instance, you only want to confirm the Delete button, not the Submit button.

Hyperlink example:

delete

<a onclick="return confirmSubmit()"href="/articles/articles/javascript/confirmsubmit.asp?ID=<%=siteID%>">delete</a><P>

The below example shows how to tie the confirmation to a single button on a form.

<form method="POST"action="/articles/articles/javascript/confirmsubmit.asp?ID=<%=siteID%>"id="submitform" name="submitform"><input type="Submit" name="Submit" value="Submit"><input type="Submit" name="Delete" value="Delete"onClick="return confirmSubmit()"></form></b><p>

The following example shows how to confirm the submission of the entire form from within the FORM tag. The form calls itself in this example, but in yours, it would likely call the processing page. Here is the code to confirm a form submission:

Inventory:

<script LANGUAGE="JavaScript"><!--// Nannette Thacker http://www.shiningstar.netfunction confirmSubmit(){var agree=confirm("Are you sure you wish to continue?");if (agree)return true ;elsereturn false ;}// --></script>

For ASP fun, I have inserted the verbiage "Deleted" dependent upon the selection. Here is the form code for those using ASP. The "&ID=AW" or "&ID=<%=siteID%>" code in the "action" is used by this web site and is not needed by your code. Those using plain Javascript can view the source code:

<b>Inventory:<p><form method="POST"action="/articles/articles/javascript/confirmsubmit.asp?shoeid=shoes&ID=<%=siteID%>"onsubmit="return confirmSubmit()" id="submitform" name="submitform">Shoes<%if request("shoeid") = "shoes" then Response.Write " Deleted " end if %><input type="Submit" value="Delete" id="Delete" name="Delete"></form><form method="POST"action="/articles/articles/javascript/confirmsubmit.asp?shoeid=socks&ID=<%=siteID%>"onsubmit="return confirmSubmit()" id="submitform" name="submitform">Socks<%if request("shoeid") = "socks" then Response.Write " Deleted " end if %><input type="Submit" value="Delete" id="Delete" name="Delete"></form></b><p>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.