Add a day with selected date using Jquery datepicker

后端 未结 3 632
北恋
北恋 2021-01-13 08:04

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

     ,
 onSelect: function(date) {
     var date2 = $(\'.currDate\         


        
相关标签:
3条回答
  • 2021-01-13 08:43
    echo date('d-m-Y', strtotime("+".$nod." days"));
    

    nod= Number of days

    0 讨论(0)
  • 2021-01-13 09:01

    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

    Update:

    $(function() {
        $('#nxtDate').datepicker({
            dateFormat: "dd-M-yy", 
        });
        $("#currDate").datepicker({
            dateFormat: "dd-M-yy", 
            minDate:  0,
            onSelect: function(date){
                var date2 = $('#currDate').datepicker('getDate');
                date2.setDate(date2.getDate()+1);
                $('#nxtDate').datepicker('setDate', date2);
            }
        });
    })
    
    0 讨论(0)
  • 2021-01-13 09:02

    setDate and getDate are the functions supported by Date() of js while you getDate from datepicker it returns as string so you need to convert it or try this code:

    onSelect: function(date) {  
         if(date!=undefined){
             var dateObject=new Date(date);
             dateObject.setDate(dateObject.getDate()+1);                                 
             $('.nextDt').datepicker('setDate', dateObject);
          }
        }
    

    Here is Demo Alerting Current and Next Date

    0 讨论(0)
提交回复
热议问题