Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

year picker in html

<select id="years">
</select>
<script>
  var currentYear= new Date().getFullYear();

  const yearselect = document.getElementById("years");
  for (let year = currentYear; year > currentYear-150; year--)
  {
    let opt = document.createElement("option");
    opt.setAttribute("value", year.toString());
    opt.innerHTML = " "  + year.toString() + " ";
    yearselect.appendChild(opt);
  }
</script>
<!--  to get the year -->
<script>
  var e = document.getElementById("years");
  var selectedYear = e.value;
</script>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #year #picker #html
ADD COMMENT
Topic
Name
1+1 =