Javascript Duplicate Order Prevention
The following code will prevent your customers from placing duplicate transactions by pressing the SUBMIT BUTTON multiple times. This simple JavaScript provides an easy solution to this problem.
Rules
- This JavaScript may not be used if you are using a Split Form. (It is built into the Split Form already.)
- The following JavaScript must be copied completely and must exist within your order form between the HTML tags of <head> and </head>.
- Find the following line in your HTML order form: <form method="post" action="(URL)" />
- Change it to: <form method="post" action="(URL)" onsubmit="return onlyonce()" />
The Code
<!-----START COPYING JAVASCRIPT HERE----->
<script language="javascript" />
<!-- numberoftimes = 0;
function onlyonce() { numberoftimes += 1; if (numberoftimes > 1) {
var themessage = "Please be patient. You have already submitted this form. Pressing submit multiple times will result in your account being billed multiple times. You will receive a response momentarily."; if (numberoftimes == 3) { themessage = "DO NOT PRESS SUBMIT MULTIPLE TIMES!!! YOUR ACCOUNT WILL BE BILLED EACH TIME YOU PRESS SUBMIT!!! Processing may take up to one minute."; } alert(themessage); return false; } else { return true; }
}
// -->
</script>
<!-----END COPYING JAVASCRIPT HERE----->