user75ponic user75ponic - 9 months ago 47
jQuery Question

Add a day with selected date using Jquery datepicker

I have been trying to add a day for another date field with date selected of current field

onSelect: function(date) {
var date2 = $('.currDate').datepicker('getDate');
$('.nextDt').datepicker('setDate', date2);

However I am getting at

Message: Object doesn't support this property or method

How can I solve this issue?

Answer Source

It is because, currDate might be empty.

If currDate is emtpy $('.currDate').datepicker('getDate') will return null in which case date2.setDate(date2.getDate()+1); could throw the error


$(function() {
        dateFormat: "dd-M-yy", 
        dateFormat: "dd-M-yy", 
        minDate:  0,
        onSelect: function(date){
            var date2 = $('#currDate').datepicker('getDate');
            $('#nxtDate').datepicker('setDate', date2);