Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using setDate with jQueryUi datepicker

I'm trying to set the date of another datepicker exactly 1 year on from the original datepicker on close.

I have the following code:

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

As you can guess this isn't working.

Any help would be great.

Thanks in advance!

Richard

like image 260
Richard L Avatar asked Jan 14 '11 14:01

Richard L


1 Answers

You can try something like that:

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

EDIT:

This is the solution to add one year, just to make sure that this is the piece which was missing right?! the on close it`s working fine right?!

like image 126
Arthur Neves Avatar answered Nov 01 '22 21:11

Arthur Neves