/    Sign up×
Community /Pin to ProfileBookmark

Form submits despite false return

Hey All,

I am working to get my form validated with JS and it seems that although the form returns false and I get the alert that a field is missing, the form still processes…hopefully you guys are seeing something im not.

[CODE]
function validate(){
with(document.forms[0]){
if(requiredCheck(fnameField) &&
requiredCheck(lnameField) &&
requiredCheck(addressField) &&
isNum(fnameField) &&
isNum(lnameField) &&
emailCheck(emailField) &&
checkForCharacter (emailField, “@”) &&
checkForCharacter (emailField, “.”)){
setCookie(); // Set form cookie
return true;
}else{
return false;
}
}
}

<form action=”form-processor.php” id=”contactForm” method=”post” onsubmit=”validate();”>
<p><span class=”reqField”>*</span>First Name: <input type=”text” name=”fnameField” id=”fnameField” size=”50″ /><br /><br />
<span class=”reqField”>*</span>Last Name: <input type=”text” name=”lnameField” id=”lnameField” size=”50″ /><br /><br />
<span class=”reqField”>*</span>Email: <input type=”text” name=”emailField” id=”emailField” size=”55″ /><br /><br />
<span class=”reqField”>*</span>Address:<br /><textarea name=”addressField” id=”addressField” cols=”47″ rows=”4″></textarea><br /><br />
Inquiry:<br /><textarea name=”inquiryField” id=”inquiryField” cols=”47″ rows=”4″></textarea><br /><br />
<input type=”submit” value=”Submit” />
<input type=”reset” value=”Reset” />
</form>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jalarieMay 07.2013 — Change
<i>
</i>onsubmit="validate();"

to
<i>
</i>onsubmit="return validate();"
×

Success!

Help @nodnarbnap 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.19,
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,
)...