Web Application Development Advice & How To
Active Server Pages Development Advice & How To

Shining Star Services LLC
Shining Star Services
ASP.net Articles
HTML Tutorial
Auto-select an Element from a Menu or Scrolling List & Save Keystrokes!
ASP Driven DHTML Slider Menus REVISITED One Year Later! Part II
ASP Driven DHTML Slider Menus
ASP Driven HTML Outlines
Reusing Code with ASP Include Files and Subroutines
Hacker Query Check
.htr IIS Security Issue
Databases, Cookies
Functions to Open a Database Connection and Record Set
Setting Up and Using OraSession to Manage Your Oracle Database Objects
Storing Non-Durable Data for Cookie-less Sessions
Smart Popups
Javascript: Validate Numeric Fields
Javascript Confirm Form Submission
Javascript Dynamic Text Area Counter
Javascript: Check All and Uncheck All Check Boxes
Javascript Field Validations -- Client Side Scripting
Tree Select Demo
Adobe Extension Manager
Scandisk & Defrag Pointers
Standards & Style
Setting Up Your Own ASP Development Templates
Creating a Project Template for Estimations of Time, Tasks, and Resources
To Host or Not To Host
ASP Naming Conventions
HTML Naming Conventions & Visual Interdev HTML Generation
Working with and in spite of the Visual Interdev Design Mode
Commenting Your ASP Source Code
Reader Letters

Articles Home

Shining Star Services

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:


<a onclick="return confirmSubmit()"

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

<form method="POST"
id="submitform" name="submitform">

<input type="Submit" name="Submit" value="Submit">

<input type="Submit" name="Delete" value="Delete"
onClick="return confirmSubmit()">


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:



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

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:


<form method="POST"
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 method="POST"
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">


ShiningStar.net | ShiningStarSingles.com | Christian911.com