btw, months in Date go from 0 to 11.
and you can decrement the month by using Date.setMonth()
and you can decrement the month by using Date.setMonth()
function dropdown(monthfield, yearfield){ var monthtext=['01','02','03','04','05','06','07','08','09','10','11','12']; var today=new Date() var monthfield=document.getElementById(monthfield) var yearfield=document.getElementById(yearfield) var thisyear=today.getFullYear() var thismonth=today.getMonth() var id = 0; for (var y=0; y<=20; y++){ for (var m=(monthtext.length-1); m>=0; m--, id++){ if(m<=thismonth){ yearfield.options[id]=new Option(thisyear+"-"+monthtext[m], thisyear+""+monthtext[m]) }else{} } thisyear-=1 thismonth = 12; } yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year }
Comment