Hello Everyone,
I am by no means a JavaScript intermediate, however I am learning. I am having a problem with validation.
When a user submits a form, I am making sure that the form content is sturctured like an email address, then if so, the form submits. However, our system checks the submission for validity… while doing so, I need to disable to submit button… this will stop the massive duplicate submissions.
Anyhow, here is what I have so far.
Email Validator:
<script type=”text/javascript”>
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf(“@”);
dotpos=value.lastIndexOf(“.”);
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,”Please enter a valid email address.”)==false)
{email.focus();return false;}
}
}
</script>
Form Tag:
<form onSubmit=”return validate_form(this);” method=”post” action=”post.php” name=”form” id=”form” >
I have tried several methods to diable the submit, but… in all cases it either checks for validity then submits and multiple submits can occour, or it disables the submit when an invalid email is tried.
How would be the best way to get this done?