/    Sign up×
Community /Pin to ProfileBookmark

Error checking

I am trying to check to be sure a form field is not empty or contain these values. It’s not working. Any help would be appreciated ?

field = form.dropOff
if (field.value == 0 || == ‘2006-04-18′,’2006-05-30′,’2006-07-04′,’2006-11-24′,’2006-12-24′,’2006-12-25′,’2007-01-01’ ) {
alert (“Your drop off date is required. No pick-ups or Drop offs on Holidays”);
field.focus();
return false;
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMar 31.2006 — Put the values in an array and then use a loop to check each value against your field value.
Copy linkTweet thisAlerts:
@susannemauthorMar 31.2006 — Thanks, but I'm not sure how to put an array in this.

<script language="JavaScript" type="text/javascript">

<!--

function valid(form) {

var field

field = form.fname

if (field.value == 0) {

alert ("Your first name is required.");

field.focus();

return false;

}

field = form.lname
if (field.value == 0) {
alert ("Your last name is required.");
field.focus();
return false;
}

field = form.pet
if (field.value == 0) {
alert ("Your pets name is required.");
field.focus();
return false;
}

field = form.telephone
if (field.value == 0) {
alert ("Your telephone number is required.");
field.focus();
return false;
}

field = form.email
if (field.value == 0) {
alert ("Your e-mail address is required.");
field.focus();
return false;
}

field = form.dropOff
if (field.value == 0 || == '2006-04-18' || == '2006-05-30' || == '2006-07-04' || == '2006-11-24' || == '2006-12-24' || == '2006-12-25' || =='2007-01-01' ) {
alert ("Your drop off date is required. No pick-ups or Drop offs on Holidays");
field.focus();
return false;
}


field = form.pickUp
if (field.value == 0 || == '2006-04-18','2006-05-30','2006-07-04','2006-11-24','2006-12-24','2006-12-25','2007-01-01' ) {
alert ("No pick-ups or Drop offs on Holidays");
field.focus();
return false;
}


// Everything checks out, submit the form
form.submit();

}
// -->
</script>
×

Success!

Help @susannem 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.16,
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,
)...