you can use the current code to check the differance between dates before saving data using JavaScript code.
The following code I used to use it in case of check dates I hope it will be useful.
function PreSaveAction()
{
var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Letter Date");
var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Decision Date");
var date3 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Request Date");
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]);
var arrDate3 = date3.value.split("/");
var useDate3 = new Date(arrDate3[2], arrDate3[1]-1, arrDate3[0]);
if(useDate1 >= useDate2)
{
alert("Letter date must be before Decision Date");
return false; // Cancel the item save process
}
else if(useDate2 >= useDate3)
{
alert("Decision Date must be before Request Date");
return false; // Cancel the item save process
}
else
{
return true; // OK to proceed with the save item
}
}
//getTagFromIdentifierAndTitle function
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[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
{
return tags[i];
}
}
return null;
}
2009/06/23
compare dates in sharepoint using JavaScript
التسميات:
JavaScript,
SharePoint
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment