Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1796 How do I stop a form from being submitted more than once

You are here: irt.org | FAQ | JavaScript | Form | 7.3 | Q1796 [ previous next ]

If a user double click a submit button or if the result takes a while to return, a form can be submitted more than once. Here is how to avoid it

<form
onSubmit="if (this.submitted) return false; this.submitted=true">

If you have validation do this:

<form
onSubmit="if (this.submitted) return false;
this.submitted=validate(this);
return this.submitted">

Or :

<script>
submitted = false;

function validate(theForm) {
   if (submitted) return false;

   noError = true;

   if (somevalidation failing) {
      noError = false
   }

   submitted = noError;
   return noError;
}
</script>

<form
onSubmit="return validate(this)">

Submitted by Michel Plungjan

©2018 Martin Webb