Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript DateTime
Hi I have 3 textboxs :-
1) StartDate
2) EndDate
3) MyDate
all the 3 of them has Date Values picked up from a Calender.
 
I want to validate them so that MyDate should be between the Start Date and End Date using Javascript.
If invalid, then I want to display a message.
How to do that?
I think we should be using custom validation controls to do that but how to implement that??
Any pointers will be helpful.
Posted 10-Jan-13 4:23am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I want to validate them so that MyDate should be between the Start Date and End Date using Javascript.
There can be various ways to do it. Simplest is to raise a JS method on any event like onclick or page submit, where you find the three controls, get the three dates and compare.
 
Sample:
function checkDateValues(startDateValue, endDateValue, myDateValue)
{
  var sDate = new Date(startDateValue);
  var eDate = new Date(endDateValue);
  var mDate = new Date(myDateValue);
  if(mDate > sDate && mDate < eDate)
  {
     // All good
     return true;
  }
  return false;
}
  Permalink  
Comments
Jashobanta at 11-Jan-13 2:35am
   
Hi Sandeep,
Thanks for the reply. But the data in my textbox will vary based on the format. How to pick up the data from textbox and then cast it into date. Once date data is there, it would be easy to compare. The data in my textbox should be 12-Feb-2013 kind of format.. any pointers?
Sandeep Mewara at 11-Jan-13 3:52am
   
Use getElementById and find the calendar controls and then the value in it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Jashobanta at 11-Jan-13 2:36am
   
Thanks Pallavi. THat was really helpfulllll...........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 Andreas Gieriet 100
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100