|
↑
Forms >>>
Do you ever receive multiple copies of a single form submission? Do your visitors click the submit button over and over, hoping it will hurry up the process? Well, JavaScript can solve your problems! The script will prevent the visitor from submitting the form after the first submission. Basic field validation also included!
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
var
submitcount=0;
function
reset()
{
document.emailform.name.value="";
document.emailform.email.value="";
document.emailform.comments.value="";
}
function
checkFields()
{
if
(
(document.emailform.name.value=="")
||
(document.emailform.email.value=="")
||
(document.emailform.comments.value=="")
)
{
alert("Please
enter your name, email, and comments then re-submit this form.");
return
false;
}
else
{
if
(submitcount
==
0)
{
submitcount++;
return
true;
}
else
{
alert("This
form has already been submitted. Thanks!");
return
false;
}
}
}
window.onload=reset;
</script>
<form
method=post
action="http://cgi.feedback.com/mail.pl"
name="emailform"
onSubmit="return
checkFields()">
<input
type=hidden
name=to
value="you@your-website-address-here.com">
<input
type=hidden
name=subject
value="Feedback
Form">
<pre>
Your Name:
<input
type=text
name="name">
Your Email:
<input
type=text
name="email">
Comments?
<textarea
name="comments"
wrap="virtual"
rows="7"
cols="45"></Textarea>
<input
type=submit
value="Submit
Form!">
[ Click the submit button twice to see
the script in action ]
</pre>
</form>
|
→
|