Hello everyone, I am new to working with Java script and could use some guidance. My goal is to create a script that adds a user-selected number of days to a date and returns the result. Currently, the script is functioning properly and storing the value in the variable expDate, however, it is in a long format such as "Wed Jan 02 2013 00:00:00 GMT+0800 (HKT)". When I attempt to split this value into different sections using the split function, my output becomes blank.
Any assistance or suggestions would be highly appreciated!
Javascript
<script type="text/javascript">
function setExpDate(){
var formDate = document.getElementById('startDate').value;
var number = +document.getElementById('days').value;
var interval = number;
var startDate = new Date(Date.parse(formDate));
var expDate = startDate;
expDate.setDate(startDate.getDate() + interval);
var splitDate = expDate.split(' ');
var monthFomatted = splitDate[1];
var dayFomatted = splitDate[2];
var yearFomatted = splitDate[3];
document.getElementById('total').innerHTML = monthFormatted;
document.getElementById('daysdays').innerHTML = Dateformatted;
};
</script>
</head>
HTML
<body>
<input type="text" size="10" maxlength="10" id="startDate" name="startDate" onblur="setExpDate(this.value)">
<select name="days" id="days" onchange="setExpDate(this.value)">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
</select>
<div id="total"></div> <br/><div id="daysdays"></div>
</body>
</html>