I am trying to create an HTML page where if the month is picked, the correct dates will display in a table.
I have a function where it gets today's month and the user is able to switch between the months, but I am unsure on how I can get all of the days.
I don't need the numbers to be displayed, just the right amount of empty table rows/table data for the month's days.
So for example, when the webpage is selected, and today's month is februari
, a empty table with the current days will display: i.e, 29 empty tables will show up - and the same if you decide to scroll to another day.
var month = new Date();
var index = month.getMonth();
var months = ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"];
document.getElementById("todayField").innerHTML = months[month.getMonth()];
function next() {
var months = ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"];
var nextMonth = index + 1 > 11 ? 0 : index + 1;
index = nextMonth
document.getElementById("todayField").innerHTML = months[nextMonth];
}
function prev() {
var months = ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"];
var nextMonth = index - 1 < 0 ? 11 : index - 1;
index = nextMonth
// console.log(nextMonth)
document.getElementById("todayField").innerHTML = months[nextMonth];
}
document.getElementById("prev").addEventListener("click", function() {
prev();
})
document.getElementById("next").addEventListener("click", function() {
next();
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>Click to change day</p>
<button type="button" name="btnPrev" onclick="prev()"><</button>
<button type="button" name="btnNext" onclick="next()">></button>
<p id="todayField"></p>
<p>You can find the days below</p>
</body>
</html>
Thanks in advance! :)