Ratna
Ratna

Reputation: 2319

how to set year in dropdown of jquery ui calender?

I have to show a datepicker for date of birth, since the year range will be about 80 years I am using the following code.

    $('#<%=txtdob.ClientID%>').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'dd/mm/yy',
        yearRange: 'c-100:c-20'
    });

it is working but whenever we change the year range it goes back 100 years!. I think I am missing something . Fiddler code is--> http://jsfiddle.net/MCheP/ Please help..

Edit: when textbox is clicked calender show up. but when I change year from 1914 to say 1920 it shows 1820 instead of 1920.

Upvotes: 1

Views: 881

Answers (5)

Karthick Kumar
Karthick Kumar

Reputation: 2361

   $( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'dd/mm/yy',
        yearRange: '-100:-20',
        defaultDate: '-100y'
    });

Demo http://jsfiddle.net/MCheP/6/

Upvotes: 1

adeneo
adeneo

Reputation: 318182

Why is there a c in there ?

$("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd/mm/yy',
    yearRange: '-100:-20',
    defaultDate: '-100y'
});

FIDDLE

the leading c sets the range relative to the selected date, so when you select a date, it sets the range back another 100 years from that date. To keep the range static you remove the c

Upvotes: 1

Aniket Sahasrabudhe
Aniket Sahasrabudhe

Reputation: 144

$( "#datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy', minDate: "-100Y", maxDate: "-20Y" });

Upvotes: 0

Sajad Karuthedath
Sajad Karuthedath

Reputation: 15767

please see the documentation

http://api.jqueryui.com/datepicker/#option-yearRange

the actual syntax/example is

$( ".selector" ).datepicker({ yearRange: "2002:2012" });

You can also use it like this also

yearRange: "-100:-20"

Upvotes: 0

Dhanu Gurung
Dhanu Gurung

Reputation: 8840

Try following for yearRange:

yearRange: "-80:+0",

DEMO

Upvotes: 1

Related Questions