Skip to content

Instantly share code, notes, and snippets.

@aizatto
Created September 18, 2011 09:54
Show Gist options
  • Save aizatto/1224927 to your computer and use it in GitHub Desktop.
Save aizatto/1224927 to your computer and use it in GitHub Desktop.
jQuery UI Datepicker - Modify another datepicker based on the difference of the last value and newly selected value
$('#form_starts_at').datepicker('option', 'onSelect', function(dateText, inst) {
var then = $.datepicker.parseDate(inst.settings.dateFormat, inst.lastVal);
var now = $.datepicker.parseDate(inst.settings.dateFormat, dateText);
var distance = now.getTime() - then.getTime();
var ends_at = $("#form_ends_at").datepicker('getDate')
ends_at.setTime(ends_at.getTime() + distance);
$("#form_ends_at").datepicker('setDate', ends_at);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment