As pointed out in the comments, I think there is enough info on the duplicate questions to solve this. But in case your looking for something specific to your code sample, my suggestion is to split 'MM/DD/YYYY' by '/' and use the date objects setMonth
, setDate
and setFullYear
methods.
function datechange() {
var d = document.getElementById('days').value;
var myDate = new Date();
var d1Value = document.getElementById('date1').value;
var ddmmyyyy = d1Value.split('/');
myDate.setDate (ddmmyyyy[0]);
myDate.setMonth(ddmmyyyy[1] - 1); // January is index 0
myDate.setFullYear (ddmmyyyy[2]);
myDate.setDate(myDate.getDate() + parseInt(d)); // add value of d
document.getElementById('date2').value = myDate.getDate()
+ '/' + (myDate.getMonth() + 1)
+ '/' + myDate.getFullYear();
}