Reputation: 53
i know, a similar question has been asked before, but i'm not understanding the answer/i feel it doesn't solve my problem. I can´t set the date in my input type date.
export default function NewNoteModal() {
return(
<div id = "newNoteModal">
{minimumSetDate()}
<div id = "newNote-header">
<h2>NoteKeeper</h2>
</div>
<form id = "newNote-content">
<label htmlFor = "noteName">Note Name:</label>
<input type="text" id = "noteName"></input>
<br></br>
{/* ---------------------- */}
<label htmlFor="checkB-important">Important:</label>
<input type="checkbox" name="important" value="important" id = "checkB-important"></input>
<br></br>
{/* ---------------------- */}
<label htmlFor="remindDate">Remind me on:</label>
<input type="date" name="remindDate" id = "remindDate"></input>
<br></br>
{/* ---------------------- */}
</form>
</div>
);
}
function minimumSetDate(){
let today = new Date();
let day = today.getDate(); // typeof = number
let month = ('0' + (today.getMonth()+1)).slice(-2); // typeof = number
let year = today.getFullYear(); // typeof = number
let currentDate = `${year}-${month}-${day}`; // typeof = string;
console.log(typeof(currentDate), currentDate);
document.getElementById("remindDate").value = currentDate;
}
the console gives "TypeError: Cannot set property 'value' of null";
however this in w3schools, works
document.getElementById("myDate").value = "2014-02-09";
Upvotes: 0
Views: 3181
Reputation: 3714
let today = new Date();
let day = today.getDate(); // typeof = number
let month = ('0' + (today.getMonth()+1)).slice(-2) // typeof = number
let year = today.getFullYear(); // typeof = number
let currentDate = `${year}-${month}-${day}`; // typeof = string;
document.getElementById("remindDate").value = currentDate;
<input type="date" id="remindDate">
Upvotes: 1