Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a jquery dropdown year selector [closed]

Tags:

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

like image 502
Nicola Peluchetti Avatar asked Apr 11 '11 12:04

Nicola Peluchetti


People also ask

How can I get the selected value of a drop down list with jQuery?

Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.

How can create drop down list in jQuery?

$('#Crd'). val() will give you the selected value of the drop down element. Use this to get the selected options text.

How remove all options from dropdown in jQuery?

To remove all options from a select list using jQuery, the simplest way is to use the empty() method.


2 Answers

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)); } 
like image 65
Jimmy Sawczuk Avatar answered Sep 23 '22 07:09

Jimmy Sawczuk


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));         }     } }); 
like image 20
VLADISLAV BOGOMOLNY Avatar answered Sep 20 '22 07:09

VLADISLAV BOGOMOLNY