/    Sign up×
Community /Pin to ProfileBookmark

Validation Question

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?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @cooljonathan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...