Many of the methods you are using seem to be incorrect, particularly those related to Date. It would be beneficial for you to refer to an updated and functional example.
(function myFunction() {
function calendar(month, year) {
var padding = "";
var totalfeb = "";
var i = 1;
var current = new Date();
var cmonth = current.getMonth();
var day = current.getDate();
var tempmonth = month + 1;
var prevmonth = month - 1;
if (month == 1) {
if ((year % 100 !== 0) && (year % 4 === 0) || (year % 400 === 0)) {
totalfeb = 29;
} else {
totalfeb = 28;
}
}
var monthnames = ["jan", "feb", "march", "april", "may", "june", "july", "aug", "sept", "oct", "nov", "dec"];
var daynames = ["sunday", "monday", "tuesday", "wednesday", "thrusday", "friday", "saturday"];
var totaldays = ["31", "" + totalfeb + "", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"];
var tempdate = new Date(tempmonth + ' 1 ,' + year);
var tempweekday = tempdate.getDay();
var tempweekday2 = tempweekday;
var dayamount = totaldays[month];
while (tempweekday > 0) {
padding += "<td class='premonth'></td>";
tempweekday--;
}
while (i <= dayamount) {
if (tempweekday2 > 6) {
tempweekday2 = 0;
padding += "</tr><tr>";
}
if (i == day && month == cmonth) {
padding += "<td class='currentday' onmouseover='this.style.background=\"#00ff00\"; this.style.color=\"#ffffff\"' onmouseout='this.style.background=\"#ffffff\"; this.style.color=\"#00ff00\"'>" + i + "</td>";
} else {
padding += "<td class='currentmonth' onmouseover='this.style.background=\"#00ff00\"' onmouseout='this.style.background=\"#ffffff\"'>" + i + "</td>";
}
tempweekday2++;
i++;
}
var calendartable = "<table class='calendar'> <tr class='currentmonth'><th colspan='7'>" + monthnames[month] + " " + year + "</th></tr>";
calendartable += "<tr class='weekdays'> <td>sun</td> <td>mon</td> <td>tues</td> <td>wed</td> <td>thurs</td> <td>fri</td> <td>sat</td> </tr>";
calendartable += "<tr>";
calendartable += padding;
calendartable += "</tr></table>";
document.getElementById("calendar").innerHTML += calendartable;
}
function displayCalendar() {
for (i = 0; i < 12; i++) {
calendar(i, 2020);
}
}
var el = document.getElementById("clickMe");
if (el.addEventListener)
el.addEventListener("click", displayCalendar, false);
else if (el.attachEvent)
el.attachEvent('onclick', displayCalendar);
})();
<button type="button" class="btn btn-secondary" id ="clickMe">Load Calendar</button>
<div id="calendar"/>