Solution 1 :

change this line:

$('#retrieveDate').text($.datepicker.formatDate('yy-dd-mm', myDate));

by this: to add text by jQuery you should use val()

$('#retrieveDate').val($.datepicker.formatDate('yy-dd-mm', myDate));

Solution 2 :

Maybe the problem is your declaration of ‘myDate’ as var and then trying to write it as a text. Try converting myDate to a String after you add 15 days.

Problem :

I picked this code from jQuery forum.

$(function () {
        dateFormat: 'yy-mm-dd',
        onSelect: function(_date) {
            var myDate = $(this).datepicker('getDate');
            myDate.setDate(myDate.getDate() + 15);
            $('#retrieveDate').text($.datepicker.formatDate('yy-dd-mm', myDate));
<script src=""></script>
<script src=""></script>
<div class="form-group">
    <label>Selected Date in Datepicker</label>
    <input type="text" name="selected_date" class="form-control datepicker"
<div class="form-group">
    <label>Retrieve Date</label>
    <input type="text" id="retrieveDate" name="retrieve_date"

When I select the date in first input, the second input must be automatically filled with the date that is 15 days more from the selected date in the datepicker.


Comment posted by Roland Starke

Inputs usually have values, can you try changing

Comment posted by Rick Bronger

just use .val(..) instead of .text(…) .val is used for inputfields. text is used for non inputfields

Comment posted by jQuery UI’s Datepicker component documentation shows it has a

jQuery UI’s Datepicker component documentation shows it has a setDate function for this purpose

Comment posted by sd077

Thanks It worked. I had tried using .val() but don’t why it didn’t work and now it is working. Thank you all.

Comment posted by Roland Starke

It looks like there are 2 date formats


Leave a Reply

Your email address will not be published. Required fields are marked *