I have a form with three fields, "start_date", "days", "end_date". I would like to get the end date by adding days to the start date.
My jQuery code is:
$("#days").change(function(){
var start_date = new Date($("#start_date").attr('value'));
var days = parseInt($("#days").attr('value'))-1;
var end_date = new Date(start_date);
end_date.setDate(start_date.getDate() + days);
$("#end_date").val(end_date.getFullYear() + '-' + ("0" + (end_date.getMonth() + 1)).slice(-2) + '-' + ("0" + end_date.getDate()).slice(-2));
});
In the "end_date" field I get "NaN-aN-aN".
What am I doing wrong?