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 %>
|