Amreesh Sharma

Amreesh Sharma

  • NA
  • 16
  • 3.4k

Facing problem in WSS calendar: Urgent

Oct 1 2008 6:23 AM
I am building a leave application in WSS 3.0. in this calendar i am using form of the calendar in which i have two fields namely Leave Start Date and Leave End Date. I am trying to validate and compare these two dates using the following javascript code. The method PreSaveAction is in FORM.js file  of the D:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033 folder.

function PreSaveAction()
{
   var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","EventDate");
   var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","EndDate");
   var arrDate1 = date1.value.split("/");
  var useDate1 = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0]);
  var arrDate2 = date2.value.split("/");
  var useDate2 = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0]);
    if(useDate1 > useDate2)
   {
       alert("The Leave End Date cannot happen earlier than the Leave Start Date");
       return false; // Cancel the item save process
   }
    return true;  // OK to proceed with the save item

And here is the function called getTagFromIdentifierAndTitle

function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++)
  {
    var tempString = tags.id;
    if (tags.title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
    {
      return tags;
    }
  }
  return null;
}

Please write solution for this querry. and suggest the appropriate alternative for this.