The javaScript year drop down box contains the current year plus or minus 50 years

  • 2020-03-30 03:09:42
  • OfStack

Javascript drop-down list box for the current year and 50 years before and after, with the current year selected by default
<script language="javascript" type="text/javascript"> 
//Sets the year selection
var myDate= new Date(); 
var startYear=myDate.getFullYear()-50;//The starting date
var endYear=myDate.getFullYear()+50;//End of the year
var obj=document.getElementById('myYear') 
for (var i=startYear;i<=endYear;i++) 
obj.options.add(new Option(i,i)); 
<select id="myYear"></select> 

Related articles: