0

i have problem with date validation in javascript

the problem is i have popup calendar the return a date value i want to check the date in javascript before send it to parent page

in popup calendar.aspx

function passDateValue(DateValue)
{
    window.returnValue=DateValue;
    window.close();
    return false;
}

in popup calendar codebehind

ClientScript.RegisterStartupScript(GetType(), "SelectDate", "passDateValue('" + clrPopUp.SelectedDate.ToShortDateString() + "')", true);

the function that call the popup calendar and check the returned value

function Calendar_popup(tbClientID)
{  
   var today = new Date();

   var Day = today.getDate();

   var Month = today.getMonth()+1;

   var Year = today.getFullYear();

   if(Month<10){Month = '0'+Month;}

   if(Day<10){Day = '0'+Day;}

   var todayFormat = Day + "/" + Month + "/" + Year;

   datevalue = window.showModalDialog("Calendar_Dialog.aspx?ctlid=" +       tbClientID, '',"dialogHeight:250px;dialogWidth:300px;");

   var startdate = Date.parse(datevalue);

   var enddate = Date.parse(todayFormat);

   if (startdate>enddate)
   {alert('BirthDate Must be less than today');
   return;
   }
}

is there anyway to check date ?

thanks!

SLiFeR14
  • 3
  • 1
  • 2

1 Answers1

0

Check out date.js, specifically...

http://code.google.com/p/datejs/wiki/APIDocumentation#compare

Compares the first date to the second date and returns an number indication of their relative values. -1 = this is < date. 0 = values are equal. 1 = this is > date.

The isAfter() and the isBefore() methods might be useful for your problem :)

Download the library here:

http://code.google.com/p/datejs/downloads/detail?name=date.js&can=2&q=

Hristo
  • 45,559
  • 65
  • 163
  • 230
  • thanks for this reference , but when i used Date.Compare() the debugger give Runtime error (Object doesn't support this property or method ) i dont know why – SLiFeR14 Apr 19 '12 at 07:26
  • you have to import the library! download it, include it in your html, and then it should work – Hristo Apr 19 '12 at 07:31