how can I set field EndDate automatically to value of field EventDate with jQuery after user choice EventDate from calendar?

I use code, but it doesn't work for me:

$(document).ready(function() {

    onSelect: function(date){
        var dates = $(this).datepicker('getDate');

1 Answer 1


Try this below code:

$(document).ready(function () {
        dateFormat: "dd-M-yy",
        minDate: 0,
        onSelect: function () {
            var dt2 = $('#EndDate');
            var startDate = $(this).datepicker('getDate');
            //add 0 days to selected date
            startDate.setDate(startDate.getDate() + 0);
            var minDate = $(this).datepicker('getDate');
            //minDate of dt2 datepicker = dt1 selected day
            dt2.datepicker('setDate', minDate);
            //sets dt2 maxDate to the last day of 30 days window
            dt2.datepicker('option', 'maxDate', startDate);
            //first day which can be selected in dt2 is selected date in dt1
            dt2.datepicker('option', 'minDate', minDate);
            //same for dt1
            $(this).datepicker('option', 'minDate', minDate);
        dateFormat: "dd-M-yy"
  • thank you for your response. Sorry for stupid question but what I have to change insted #EventDate and #EndDate? Field ID or FieldInternalName? With or within " " or ' ' or "#"? Oct 10, 2016 at 16:40
  • my html looks like this: <input id="EventDate" type="text" /> <input id="EndDate" type="text" /> Oct 11, 2016 at 4:58
  • so id should be that of the <input> tag Oct 11, 2016 at 8:50
  • Thank you, it works but only if I change date in a field EventDate, not from calendar beside this field od EventDate. Could you add some code to do this? Oct 17, 2016 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.