Here is the working code, made few fixes like we need to use getDate() instead of getDay(), (today.getMonth() + 1) and handled season5[0].
http://jsfiddle.net/sahilbatla/p7rfcLgt/
<script>
function compareDate() {
console.log("Function fired");
var today = new Date();
var todayDate = today.getFullYear() + "," + (today.getMonth() + 1) + "," + today.getDate() + "," + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
console.log(todayDate)
if (Date.parse(todayDate) > Date.parse('12/20/2014')) {
document.getElementById("testDate").innerHTML = "111";
console.log("111");
} else {
document.getElementById("testDate").innerHTML = "222";
console.log("222");
}
}
</script>
<body class="addbackground" onload="compareDate()">
<div id="testDate"></div>
</body>
2
solved JavaScript onload function not executing [closed]