Selected Date +15 Days in other Textbox Using jquery Datepicker

By | May 9, 2013


In many projects we have to calculate the future dates. Ex- We have 2 fields and we have a jquery datepicker in one textbox and another one is normal textbox. Now what we want is when we select date from datepicker other textbox will show the selected date + 15 Days ex- I select 09-05-2013 now other textbox will show 24-05-2013. So lets check it our here

Live Demo

You can use the below code for this.

HTML

<input type="text" id="mydate" name="mydate">
<br/>
<input type="text" id="newdate" name="newdate">

 Jquery

$(function () {
$("#mydate").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function (selectedDate) {
if (this.id == 'mydate') {
var dateMin = $('#mydate').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 15);
$('#newdate').val($.datepicker.formatDate('mm/dd/yy', new Date(rMax)));
}
}
});
});

You can use this code into your project whenever you need it. Happy Codeing !!!

Leave a Reply

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