How to add one day to the calendar date selected using jquery ui

I recently has an email come into me asking about a previous post I did regarding the jQuery UI date picker. This person was looking for a way to add some extra functionality to the date picker example I had that would auto default to setting the drop off date textbox value to be one day ahead of the pickup date.

To do this all that is required is to add an extra function within the document.ready() function that fires when the pickup date is changed, add one to the date entered and then put that value into the drop off box. The code to do this is:

$('.pUpDate').change(function() {
    var nextDayDate = $('.pUpDate').datepicker('getDate', '+1d');
    nextDayDate.setDate(nextDayDate.getDate() + 1);
    $('.dOffDate').datepicker('setDate', nextDayDate);

Building on the previous examples demo, below is a link to download a working example that includes the above new code snippet.

Download this demo

blog comments powered by Disqus

Get In Touch

Follow me online at TwitterFacebook or Flickr.

Latest Tweets