0

Hi I have the following script. I want to change the year to 25 years from current year dynamically without hardcoding.

$(document).ready(function () {
    var dateOfBirth = $('[data-id="dateOfBirth"]');
    dateOfBirth.datepicker("option", "dateFormat", "ddmmyy");
    dateOfBirth.prop("placeholder", "ddMMyyyy");
    dateOfBirth.prop("aria-label", "ddMMyyyy");

    var currentDate = new Date();
    $('[data-id="dateOfBirth"]').datepicker({
        format: 'ddMMyyyy',
        autoclose: true,
        endDate: "currentDate",
        maxDate: currentDate,
        showButtonPanel: false
    }).change(dateChanged)
        .on('changeDate', dateChanged);
});

function dateChanged(ev) {
    $(this).datepicker('hide');
    $(this).blur();
}

As of now it shows 10 years from current year when clicked on year drop down. PFB the screenshot for your references.

enter image description here

I am trying to find the solution and learn in the process. Thanks.

Jaay
  • 2,103
  • 1
  • 16
  • 34
Mahi
  • 553
  • 2
  • 7
  • 23
  • Does this answer your question? [jQuery UI Datepicker Range](https://stackoverflow.com/questions/3827425/jquery-ui-datepicker-range) – DarkBee Oct 18 '22 at 07:37

1 Answers1

0

You can do it:

$('[data-id="dateOfBirth"]').datepicker({
        format: 'ddMMyyyy',
        autoclose: true,
        endDate: "currentDate",
        maxDate: currentDate,
        minDate: new Date("-25y"),
        showButtonPanel: false
    })

https://api.jqueryui.com/datepicker/#option-minDate

zvi
  • 3,677
  • 2
  • 30
  • 48