Difference between revisions of "Date Validation"
From All n One's bxp software Wixi
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...") |
Philip Lacey (talk | contribs) |
||
| Line 4: | Line 4: | ||
<source lang="javascript" collapse="true" first-line="2"> | <source lang="javascript" collapse="true" first-line="2"> | ||
| − | function fn_ValidateDate ( autoFill, originalPlus ) { | + | function fn_ValidateDate ( autoFill, originalPlus, strFieldName, strFieldCustom ) { |
| − | var autoDate | + | var autoDate = autoFill; |
| − | var daysPassed | + | var daysPassed = originalPlus; |
| − | var flag | + | var flag ='False'; |
| − | var selectedDate | + | var selectedDate = document.getElementById(strFieldCustom).value; |
| − | var dateToCheck | + | var dateToCheck = new Date(document.getElementById(strFieldCustom).value); |
| − | document.getElementById( | + | document.getElementById(strFieldName).value = selectedDate; |
| − | var dayOfWeek=dateToCheck.getDay(); | + | var dayOfWeek = dateToCheck.getDay(); |
if (dayOfWeek == 6){ | if (dayOfWeek == 6){ | ||
| Line 22: | Line 22: | ||
else{ | else{ | ||
alert("Date auto selected for "+ originalPlus +" days from today is a Saturday. This has now been changed to the following Monday"); | alert("Date auto selected for "+ originalPlus +" days from today is a Saturday. This has now been changed to the following Monday"); | ||
| − | daysPassed = daysPassed + 2; | + | daysPassed = daysPassed + 2; |
| − | flag = 'True'; | + | flag = 'True'; |
TodayPlusXDays(daysPassed); | TodayPlusXDays(daysPassed); | ||
} | } | ||
| Line 33: | Line 33: | ||
else{ | else{ | ||
alert("Date auto selected for "+ originalPlus +" days from today is a Sunday. This has now been changed to the following Monday"); | alert("Date auto selected for "+ originalPlus +" days from today is a Sunday. This has now been changed to the following Monday"); | ||
| − | daysPassed = daysPassed + 1; | + | daysPassed = daysPassed + 1; |
| − | flag = 'True'; | + | flag = 'True'; |
TodayPlusXDays(daysPassed); | TodayPlusXDays(daysPassed); | ||
} | } | ||
| Line 45: | Line 45: | ||
else{ | 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"); | 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; | + | daysPassed = daysPassed + 1; |
| − | flag = 'True'; | + | flag = 'True'; |
TodayPlusXDays(daysPassed); | TodayPlusXDays(daysPassed); | ||
} | } | ||
| Line 52: | Line 52: | ||
} | } | ||
| − | if((document.getElementById( | + | if((document.getElementById(strFieldCustom).value != ' ') && (flag == 'False')){ |
| − | var setDateOriginal = document.getElementById( | + | var setDateOriginal = document.getElementById(strFieldCustom).value; |
| − | var Current_Date = setDateOriginal.split('/'); | + | var Current_Date = setDateOriginal.split('/'); |
| − | var newDateToPopulate = Current_Date[1] + '/' + Current_Date[0] + '/' + Current_Date[2]; | + | var newDateToPopulate = Current_Date[1] + '/' + Current_Date[0] + '/' + Current_Date[2]; |
| − | document.getElementById( | + | document.getElementById(strFieldCustom).value = newDateToPopulate; |
| − | document.getElementById( | + | document.getElementById(strFieldName).value = newDateToPopulate; |
} | } | ||
} | } | ||
</source> | </source> | ||
Revision as of 18:32, 19 March 2014
JavaScript Date Validation script
function fn_ValidateDate ( autoFill, originalPlus, strFieldName, strFieldCustom ) {
var autoDate = autoFill;
var daysPassed = originalPlus;
var flag ='False';
var selectedDate = document.getElementById(strFieldCustom).value;
var dateToCheck = new Date(document.getElementById(strFieldCustom).value);
document.getElementById(strFieldName).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(strFieldCustom).value != ' ') && (flag == 'False')){
var setDateOriginal = document.getElementById(strFieldCustom).value;
var Current_Date = setDateOriginal.split('/');
var newDateToPopulate = Current_Date[1] + '/' + Current_Date[0] + '/' + Current_Date[2];
document.getElementById(strFieldCustom).value = newDateToPopulate;
document.getElementById(strFieldName).value = newDateToPopulate;
}
}