Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I only allow a submit to be clicked only once? 1

Status
Not open for further replies.

WildWest

Programmer
Apr 2, 2002
111
0
0
US
Does anyone know how I can only allow a submit to be clicked only once? My users are clicking twice and messing up my database. Please help if you can and thanks in advance.

 
I'm pretty sure that users can't submit twice by clicking the button real fast, but just in case this should stop them:
Code:
<script language=JavaScript>

submitFlag = true;

function checkSubmit() {
   if (submitFlag) {
      submitFlag = false;
      return true;
   }
   return false;
}

</script>
<body>
<form name=blahForm onsubmit='return(checkSubmit())'>
<input type=submit value='Click Me'>
</form>
</body>

-kaht

banghead.gif
 
While this may solve the issue of someone getting impatient while waiting for the next page to download and clicking Submit again, this is not a complete solution. What if the user uses the browser's Back button to go back in the page history? In such a case they could submit the page yet again. (This may depend on the client browser page cache settings, etc.)

If you really must prevent any sort of double submissions, you may have to code for that. For example, when you create the page for the user, you could include a hidden element containing a unique key that you could check once submitted. If it had been sent before, then reject it.

I know of one online brokerage firm who didn't do that simple checking via unique keys for pending-transaction and therefore someone could (and did!) reprocess requests/orders again just by going back and displaying a page in history. Sheesh! Of course they denied it could happen. But it did.

dbMark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top