saemirii / checkmate.github.io

a minimalistic task manager
https://checkmate-github-io.vercel.app
11 stars 4 forks source link

date picker logging null values #4

Closed saemirii closed 3 months ago

saemirii commented 3 months ago

function showCalendarPicker(event) {
    const datePicker = document.getElementById("datepicker");

    // Show the date picker immediately when the calendar button is pressed
    datePicker.style.display = "block";

    // Set the position of the date picker next to the cursor
    datePicker.style.left = event.pageX + 10 + "px";
    datePicker.style.top = event.pageY - 20 + "px";

    // Function to handle confirmation after selecting a date
    function handleConfirmation() {
        const confirmation = confirm("Is this the correct schedule?");
        if (!confirmation) {
            // If the user cancels, hide the date picker
            datePicker.style.display = "none";
        }
    }
    document.addEventListener("keydown", function(event) {
        if (event.key === "Enter") {
            handleConfirmation();
     var dateValue = document.getElementById('dateInput').value;
     var selectedDate = new Date(dateValue);
     var year = selectedDate.getFullYear();
     var month = selectedDate.getMonth() + 1;
     var day = selectedDate.getDate();
    console.log("Year:", year, "Month:", month, "Day:", day);
        }
    });
}```

I have a date picker. When I click the calendar icon, the date picker appears. When I select a date and press enter, the popup will ask me to confirm the date. the problem now is that the values from the date picker are null or undefined, which can be seen when I log it.