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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply