Search code examples
javascripthtmlleap-year

How to Bind Years in DropdownList


Here I have a task that Years Should be Bind in DropdownList Like 1947 to 2016 if I write Code Like

<select>
    <option value="1947">1947</option>
    <option value="2016">2016</option>

</select>

Its Taken whole day


Solution

  • This could be done by javascript for example:

    <select id="year"></select>
    

    JScript:

    var year = 1947;
    var till = 2016;
    var options = "";
    for(var y=year; y<=till; y++){
      options += "<option>"+ y +"</option>";
    }
    document.getElementById("year").innerHTML = options;