Solved

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

Posted on 2009-03-28
3
245 Views
Last Modified: 2012-05-06
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?

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

Open in new window

0
Comment
Question by:coleventures
3 Comments
 
LVL 30

Accepted Solution

by:
third earned 500 total points
ID: 24012439
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);"
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24012814
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

0
 
LVL 3

Author Closing Comment

by:coleventures
ID: 31563980
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JS Plugin 4 29
Javascript closure 1 36
alert before form submission 6 31
would you please explain me the conditional part ? 4 12
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now