is there a jQuery plugin that creates automatically a dropdown year selector (that is a "select" element poulated with all years starting from current and dating back to a given year)?
I don't need day/month (otherwise i'd have used the datepicker), i just need the year!
Thanks in advance
Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.
$('#Crd'). val() will give you the selected value of the drop down element. Use this to get the selected options text.
To remove all options from a select list using jQuery, the simplest way is to use the empty() method.
What about just:
<select name="yearpicker" id="yearpicker"></select>
And then:
for (i = new Date().getFullYear(); i > 1900; i--) { $('#yearpicker').append($('<option />').val(i).html(i)); }
Wrapping around the code into jQuery plugin to select years between start and end year:
jQuery.extend(jQuery.fn,{ /* ** Year selection plugin ** Sample usage ** $('#yearpicker').years(2007, 2017); ** ** HTML ** <select name="yearpicker" id="yearpicker"></select> */ years: function(start, end) { for (i = start; i <= end; i++) { $(this).append($('<option />').val(i).html(i)); } } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With