/    Sign up×
Community /Pin to ProfileBookmark

Simple form validation question

I have a basic form fields required validation script (which I finally got working) but after I click on the alert box “ok” button the form submits anyway. I’ve tried a variety of fixes none of which stopped the form submission.

Thanks for any help! David

</script>

<script language=”JavaScript” type=”text/javascript”>
function validateFields() {
if (document.myForm.firstname.value == “”) {
alert(“Please Enter Your First Name”)
return false
}
if (document.myForm.lastname.value == “”) {
alert(“Please Enter Your Last Name”)
return false
}
if (document.myForm.email.value == “”) {
alert(“Please Enter Your Email Address”)
return false
}
if (document.myForm.phone.value == “”) {
alert(“Please Enter Your Telephone Number”)
return false
}
if (document.myForm.address1.value == “”) {
alert(“Please Enter Your Address”)
return false
}
if (document.myForm.city.value == “”) {
alert(“Please Enter Your City”)
return false
}
if (document.myForm.state.value == “”) {
alert(“Please Enter Your Password”)
return false
}
if (document.myForm.zip.value == “”) {
alert(“Please Enter Your Zip Code”)
return false
}
if (document.myForm.social.value == “”) {
alert(“Please Enter Your Social Security Number”)
return false
}
if (document.myForm.birthdate.value == “”) {
alert(“Please Enter Your Birth Date”)
return false
}
if (document.myForm.creditCardNumber.value == “”) {
alert(“Please Enter Your Credit Card Number”)
return false
}
if (document.myForm.cvv2Number.value == “”) {
alert(“Please Enter Your Credit Card Validation Number”)
return false
}
if (document.myForm.authorize.value == “”) {
alert(“You must choose to Authorize Enrollment to proceed”)
return false
}
if (document.myForm.privacy.value == “”) {
alert(“You must accept the Privacy Policy to proceed”)
return false
}
if (document.myForm.terms.value == “”) {
alert(“You must agree with the Terms and Conditions to proceed”)
return false
}

return true

}
</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 18.2007 — Does the form have a [I]return[/I]?&lt;form name="info" action="info.php" onsubmit="[COLOR="Green"]return [/COLOR]validateFields();" enctype="multipart/form-data" method="post"&gt;
Copy linkTweet thisAlerts:
@inkfastauthorOct 18.2007 — It does now! Thanks I must be losing it.
×

Success!

Help @inkfast 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.20,
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,
)...