Javascript confirm form submission

Source: Internet
Author: 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/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/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 callitself in this example, but in yours, it wowould 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:

  Inventory: 

Shoes <% if request (" shoeid ") =" Shoes "then response. write "deleted" end if %> socks <% if request (" shoeid ") =" Socks "then response. write "deleted" end if %>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.