Date Validation

Revision as of 18:22, 19 March 2014 by Philip Lacey (talk | contribs) (Created page with "JavaScript Date Validation script <source lang="javascript" collapse="true" first-line="2"> function fn_ValidateDate ( autoFill, originalPlus ) { var autoDate = autoFi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Revision as of 18:22, 19 March 2014 by Philip Lacey (talk | contribs) (Created page with "JavaScript Date Validation script <source lang="javascript" collapse="true" first-line="2"> function fn_ValidateDate ( autoFill, originalPlus ) { var autoDate = autoFi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

JavaScript Date Validation script


function fn_ValidateDate ( autoFill, originalPlus ) {
	 
	var autoDate		= autoFill;
	var daysPassed		= originalPlus;
	var flag			='False';
	var selectedDate 	= document.getElementById('strCDA_29_field_0_87_Custom').value;
	var dateToCheck 	= new Date(document.getElementById('strCDA_29_field_0_87_Custom').value);
	
	document.getElementById('strCDA_29_field_0_87').value = selectedDate;
	
	var dayOfWeek=dateToCheck.getDay();
	
	if (dayOfWeek == 6){
		if(autoFill == 0){
			alert("Date selected is a Saturday and is not allowed");
		}
		else{
			alert("Date auto selected for "+ originalPlus +" days from today is a Saturday. This has now been changed to the following Monday");
			daysPassed = daysPassed + 2;
			flag	=	'True';
			TodayPlusXDays(daysPassed);	
		}
	}
	else if (dayOfWeek == 0){
		if(autoFill == 0){
			alert("Date selected is a Sunday and is not allowed");
		}
		else{
			alert("Date auto selected for "+ originalPlus +" days from today is a Sunday. This has now been changed to the following Monday");
			daysPassed = daysPassed + 1;
			flag	=	'True';
			TodayPlusXDays(daysPassed);		
		}
	}
	for(var i=0; i <= IrishDates.length; i++){
		if(selectedDate == IrishDates[i]){
			if(autoFill == 0){
				alert("Date selected is a bank holiday in the Republic of Ireland and is not allowed");
			}
			else{
				alert("Date auto selected for "+ originalPlus +" days from today is a bank holiday in the Republic of Ireland. This has now been changed to the following day");
				daysPassed = daysPassed + 1;
				flag	=	'True';
				TodayPlusXDays(daysPassed);	
			}
		}
	}
	
	if((document.getElementById('strCDA_29_field_0_87_Custom').value != ' ') && (flag == 'False')){
		var setDateOriginal = document.getElementById('strCDA_29_field_0_87_Custom').value; 
		var Current_Date	= setDateOriginal.split('/');
		var newDateToPopulate = Current_Date[1] + '/' + Current_Date[0] + '/' + Current_Date[2];
		document.getElementById('strCDA_29_field_0_87_Custom').value 	= newDateToPopulate;
		document.getElementById('strCDA_29_field_0_87').value 			= newDateToPopulate;	
	}	
}