Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker plugin for birth date textbox

I've found a very easy to use datepicker called jquery datepicker. But the problem is when I want to use it for birth date. For example: my birth year is 1986 and the current year is 2013, then I need to click left arrow many times to decrease the months until I find 1986. It will be more troublesome if my birth year is 1960 or below.

Does anybody know any datepicker plugin that suitable for this? Perhaps a datepicker which year or month can be selected from dropbox or something?

like image 249
Henry Gunawan Avatar asked Jan 09 '13 04:01

Henry Gunawan


1 Answers

In short: you may do that bythe Restricting Datepicker section in the demo page.

If you look down the demo page a bit, you'll see a "Restricting Datepicker" section. Use the dropdown to specify the "Year dropdown shows last 20 years" demo , and hit view source:

$("#restricting").datepicker({ 
    yearRange: "-20:+0", // this is the option you're looking for
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true 
});

You'll want to do the same (obviously changing -20 to -100 or something).

Option # 2: is using the changeMonth and changeYear options of the api.

Try using 'yy' for the current year like:

$('.datepicker').datepicker({changeYear: true, yearRange : 'yy-50:yy+1'});

for more information view http://api.jqueryui.com/datepicker/#option-yearRange

like image 122
Yusubov Avatar answered Oct 09 '22 20:10

Yusubov