Using setDate with jQueryUi datepicker

I am trying to set the date of another datepicker exactly 1 year from the original datepicker when closing.

I have the following code:

$("#myDatepicker1").datepicker({ onClose: function(dateText, inst) { $("#myDatepicker2").datepicker("setDate", dateText +1y); } }); 

As you can guess, this does not work.

Any help would be great.

Thanks in advance!

Richard

+8
javascript jquery jquery-ui datepicker
source share
1 answer

You can try something like this:

 d = $("#myDatepicker1").datepicker("getDate"); $("#myDatepicker2").datepicker("setDate", new Date(d.getFullYear()+1,d.getMonth(),d.getDate())); 

EDIT:

This decision to add one year, just to make sure that this is the part that was missing correctly ?! at closing it works fine ??

+18
source share

Source: https://habr.com/ru/post/651066/


All Articles