javascript - i tried a html code for next and previous 5 years in a drop down.. i got next 5 years properly.. how can i get previous 5 years -


i tried html code next , previous 5 years in drop down.. got next 5 years properly.. how can previous 5 years

please he;p me code

function populatedropdown(yearfield){ var today=new date() var yearfield=document.getelementbyid(yearfield) var thisyear=today.getfullyear() (var y=0; y<5; y++){ yearfield.options[y]=new option(thisyear, thisyear) thisyear+=1 } yearfield.options[0]=new option(today.getfullyear(), today.getfullyear(), true, true) //select today's year }  </script>   </head>   <body> <form action="" name="someform"> <select id="yeardropdown"> </select>  </form>  <script type="text/javascript">  //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select) window.onload=function(){ populatedropdown("yeardropdown") } </script>   </body> </html> 

try this

function populatedropdown(yearfield) {    var today = new date(),        yearfield = document.getelementbyid(yearfield),        beforeyears = 3        afteryears = 5,        thisyear = today.getfullyear();        (var year = thisyear-beforeyears, index = 0;              index <= beforeyears + afteryears;              index++, year++) {      yearfield.options[index] = new option(year, year);    }    yearfield.value = thisyear;      //select today's year  }    //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)  window.onload = function() {    populatedropdown("yeardropdown")  }
<form action="" name="someform">    <select id="yeardropdown">    </select>  </form>


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -