First, I think getYear() is (or is being) deprecated; use getFullYear(), which will give you the full four digit year.
Code:
function autoYear() {
var time = new Date();
var year = time.getFullYear();
var date = year + 25; /*change the '25' to the number of years in the past you want to show */
var future = year - 10; /*change the '10' to the number of years in the future you want to show */
document.writeln ("<form><select><option value=\"\">Select Year");
do {
date--;
document.write ("<option value=\"" +date+"\">" +date+ "");
}
while (date > future)
document.write ("</select></form>");
}
IMHO, the above is kind of a hokey way of doing it. You're better off hard-coding the SELECT in HTML without options, giving it an ID, and then after the page is loaded use getElementById and new Option. Loop through that and use new Option to add the years.
Just my $0.02 worth.
Bookmarks