Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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

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:
JavaScript
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;
}
 
Share this answer
 
Comments
Jashobanta 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 11-Jan-13 3:52am    
Use getElementById and find the calendar controls and then the value in it.
 
Share this answer
 
Comments
Jashobanta 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900