Skip to content

Instantly share code, notes, and snippets.

@QuestionDevelopment
Created August 23, 2013 19:56
Show Gist options
  • Save QuestionDevelopment/6323334 to your computer and use it in GitHub Desktop.
Save QuestionDevelopment/6323334 to your computer and use it in GitHub Desktop.
allow for form validation without leaving page
<script language="JavaScript" type="text/javascript">
<!--
function CheckForm() {
if (!(document.contactForm.name.value.length > 0))
{
alert("You must enter your Name");
contactForm.name.focus();
return false;
}
if (!(document.contactForm.email.value.length > 0))
{
alert("You must enter your Email Address");
contactForm.email.focus();
return false;
}
if (!(document.contactForm.phone.value.length > 0))
{
alert("You must enter your Phone Number");
contactForm.phone.focus();
return false;
}
if (document.contactForm.security.value != 'white')
{
alert("Your Security code is incorrect");
contactForm.security.focus();
return false;
}
return true;
}
//-->
</script>
<form action="/contact.htm" method="post" enctype="multipart/form-data" name="contactForm" id="contactForm" onSubmit="return CheckForm();">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment