J 2.5.7 F 3.0.6
I've been trying for two days without success to get this to work, with every variation I could think of. I've looked at every WIKI, forum, and google.
I'm merely trying to validate a date entered on a form as mm/dd/yyyy. I cannot figure out why this js does not work.
If I uncomment the alert('Got to JavaScript') I get that alert. But I do not get the next alert to display the date, so obviously I'm not getting it off the form. I've got this in a simple test list/form where I'm entering date1 and then a text field.
Hate to bother you with this stuff, but I need to get this working.
Thanks.
I've been trying for two days without success to get this to work, with every variation I could think of. I've looked at every WIKI, forum, and google.
I'm merely trying to validate a date entered on a form as mm/dd/yyyy. I cannot figure out why this js does not work.
Code:
// alert(Got to JavaScript');
//var dateStr = $('sky1_checkdate___date1').getValue();
var dateStr = form_32.formElements.get('sky1_checkdate___date1').getValue();
alert('Date is 'dateStr);
var DayIndex = 1;
var MonthIndex = 0;
var YearIndex = 2;
value = dateStr.replace(/-/g, "/").replace(/\./g, "/");
var SplitValue = dateStr.split("/");
var OK = true;
if (!(SplitValue[DayIndex].length == 1 || SplitValue[DayIndex].length == 2)) {
OK = false;
}
if (OK && !(SplitValue[MonthIndex].length == 1 || SplitValue[MonthIndex].length == 2)) {
OK = false;
}
if (OK && SplitValue[YearIndex].length != 4) {
OK = false;
}
if (OK) {
var Day = parseInt(SplitValue[DayIndex], 10);
var Month = parseInt(SplitValue[MonthIndex], 10);
var Year = parseInt(SplitValue[YearIndex], 10);
if (OK = ((Year > 1900) && (Year < new Date().getFullYear()))) {
if (OK = (Month <= 12 && Month > 0)) {
var LeapYear = (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0));
if (Month == 2) {
OK = LeapYear ? Day <= 29 : Day <= 28;
}
else {
if ((Month == 4) || (Month == 6) || (Month == 9) || (Month == 11)) {
OK = (Day > 0 && Day <= 30);
}
else {
OK = (Day > 0 && Day <= 31);
}
}
}
}
}
return OK;
}
catch (e) {
return false;
}
Hate to bother you with this stuff, but I need to get this working.
Thanks.