Im really new to Java script, so please bear with me. I'm trying to write a script that will return a date with the addition of a user selected number of days. It works fine as far as returning a value (in the variable expDate, however the value is in the long format (i.e. "Wed Jan 02 2013 00:00:00 GMT+0800 (HKT)) . I run into trouble when I try and break it down into different sections using split. Now my output is just blank.
Any help would be greatly 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>