SharePoint 2007 Start Date End Date Validation in List forms with JavaScript

SharePoint 2007 Start Date End Date Validation in List forms with JavaScript:

<script language="javascript"> 
function PreSaveAction()
{
	var blFlag;
	blFlag = true;

	var SOSOccDate = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Date SOS Occurred");
	var DUEDate = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Due date");
	var dtSOSOccDate = new Date(SOSOccDate.value);
	var dtDUEDate = new Date(DUEDate.value);
	var TodaysDate = new Date();

	if(dtSOSOccDate != null)
	{
		if(dtSOSOccDate > TodaysDate)
		{
			alert("Date SOS Occured cannot be greater than today's date");
		}
	}

	if(DUEDate.value != "")
	{
		if(dtDUEDate < dtSOSOccDate)
		{ 
			alert("The Due date cannot happen earlier than the SOS occurred date"); 
			blFlag = false; // Cancel the item save process 
		}
	}
	return blFlag; // OK to proceed with the save item 
}
</script>

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *