• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Can I include 2nd and subsequent validation calls in OnSubmit?

I have a javascript routine which works fine when calling from onSubmit.
This call only validates one field as I have to pass the field id (this.EDD).

Could I make a second call within this same onSubmit to another date field I want to validate?  How would I do that?

onSubmit="return checkdate(this.EDD);"

Open in new window

1 Solution
create a wrapper function,

function validate(obj){
  return checkdate(obj.EDD) && checkdate(obj.EDD2);   //i named the second date field as EDD2

then change your onsubmit call to,

onSubmit="return validate(this);"
It is also possible to place additional code within the handler:
// Or, validate multiple items.
onSubmit="return checkdate(this.EDD) && checksomething(this.something);"
// Do something and then validate date.
onSubmit="somethingElse(this.EDD); return checkdate(this.EDD);"

Open in new window

coleventuresAuthor Commented:
Your solution is the better all around answer.  It was also the first.
It works best for multiple booleans meant for onSubmit and allows the onSubmit command to stay uncomplicated.  I was looking for that ability to have two or more conditions that only returned true when all conditions were true and it seems that && (the way to represent logical AND) is the correct way to do it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now