0

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:

<script>
$(document).ready(function() {

$("#EventDate").datepicker({
    onSelect: function(date){
        var dates = $(this).datepicker('getDate');
$("#EndDate").val(dates);
    }
});
});
</script>           
0

Try this below code:

$(document).ready(function () {
    $("#EventDate").datepicker({
        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);
        }
    });
    $('#EndDate').datepicker({
        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 "#"? – David Repka Oct 10 '16 at 16:40
  • my html looks like this: <input id="EventDate" type="text" /> <input id="EndDate" type="text" /> – Gautam Sheth Oct 11 '16 at 4:58
  • so id should be that of the <input> tag – Gautam Sheth Oct 11 '16 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? – David Repka Oct 17 '16 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.