Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  56] [ 2]  / answers: 1 / hits: 39302  / 8 Years ago, tue, october 18, 2016, 12:00:00

I have two datepicker.
I wanted to set today's date as default in one datepicker, and 7 day before in another datepicker. Also I want drop-down list for selecting month and year in datepicker.



in script I wrote the code below



 $(#datepickerTo).datepicker({
dateFormat: 'mm-dd-yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',


});

$(#datepickerFrom).datepicker({
dateFormat: 'mm-dd-yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',


});


but it is not working for me.
please help me to solve this.



i also tried setDate, new Date()


More From » jquery

 Answers
32

This may work for you,try it :





var lastDate = new Date();
lastDate.setDate(lastDate.getDate() - 7);//any date you want
$(#datepickerFrom).datepicker('setDate', lastDate);




[#60361] Friday, October 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;