javascript - Populate the dropdownlist from a specfic year to current year -


i'm creating dropdownlist of year. how can automatically populate dropdownlist?

for example, adding dropdown value 1980, can use jquery populate current year, not need type year?

it's simple using loop , adding string like:

var nowy = new date().getfullyear(),      options = "";    for(var y=nowy; y>=1980; y--) {    options += "<option>"+ y +"</option>";  }    $("#years").append( options );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <select id="years"></select>

https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date/getfullyear
http://api.jquery.com/append/


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -