views:

70

answers:

1

For the datepicker control in jQuery UI, is there a way to mix absolute ranges with a relative range?

For example, how would you express, I want the year to only go back to 2005, but only show up to the current year?

I've tried mixing the two, using something like '2005:+0', but this results in no years being available in the menu.

Year Range documentation:

yearRange

Type: String Default: '-10:+10'

Control the range of years displayed in the year drop-down: either relative to current year (-nn:+nn) or absolute (nnnn:nnnn).

+2  A: 

Here you go. Just need to use a Date object to get the current year.

Working Demo

Code from Demo

$(function () 
{
    $('#txtStartDate').datepicker(
    {
        showOn: "both",
        yearRange: "2005:" + new Date().getFullYear(),
        dateFormat: "dd M yy",
        firstDay: 1, 
        changeFirstDay: false,
        changeMonth: true,
    changeYear: true

    }); 
});
Russ Cam
Oh, good idea. Thank you.
James McMahon
bang on, thanks.
dove