I am new to JavaScript and still learning as I code. I want to implement this specific JSFiddle code (http://jsfiddle.net/MCzJ6/163/) in a project but It is not working. Any help would be very appreciative.
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
</head>
<script type="text/javascript">
;(function($, window, document, undefined){
$("#days").on("change", function(){
var date = new Date($("#start_date").val()),
days = parseInt($("#days").val(), 10);
if(!isNaN(date.getTime())){
date.setDate(date.getDate() + days);
$("#end_date").val(date.toInputFormat());
} else {
alert("Invalid Date");
}
});
//From: http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
Date.prototype.toInputFormat = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
};
})(jQuery, this, document);</script>
<body>
<input type="date" id="start_date" placeholder="Start Date"/>
<input type="number" id="days" min=0 placeholder="Days"/>
<input type="date" id="end_date" placeholder="End Date" readonly/></body>
</html>