Solved

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

Posted on 2009-03-28
3
242 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

705 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

19 Experts available now in Live!

Get 1:1 Help Now