JavaScript - prevent multiple form submittals

Often times we need to prevent a user from submitting the same form twice. This issue becomes especially important with slow connections. Here is a small JavaScript sample of how to prevent duplicate form submittals:

Often times we need to prevent a user from submitting the same form twice. This issue becomes especially important with slow connections. Here is a small JavaScript sample of how to prevent duplicate form submittals:


<SCRIPT language=JavaScript >

var submitcount=0;

function checkSubmit()
{

if (submitcount == 0)
{ submitcount++; return true; }
else
{ alert('This form has already been submitted.' ); return false; }

}

</SCRIPT>

<form name=frmSubmit method=post onSubmit=" return checkSubmit();" action="mypage.asp" >


Submission Date:  9/23/2005 3:03:18 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (506 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP