How can I get the code below to work when I have a month of february? Currently it is getting to the day and then stopping before getting to the if to determine whether it is a leap year.
if (month == 2) {
if (day == 29) {
if (year % 4 != 0 || year % 100 == 0 && year % 400 != 0) {
field.focus();
field.value = month +'/' + '';
}
}
else if (day > 28) {
field.focus();
field.value = month +'/' + '';
}
}
day
for values of 29 or greater (based on theday == 29
andday > 28
if clauses). I'm assuming that you meant to writeday <= 28
, but if that's the case, you could drop the secondelse if
clause and use anelse
clause directly. It might also be safer to add an additional set of parenthesis to your leap year clause:if (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0))
– Iridotomy