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 - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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