AnthonyFink,
пробуйте, и пишите в чём проблема?
newNote();
function saveToDo(){
// take date of new note
var date = new Date()
// take note
var getId = date.getTime();
var getNote = document.getElementById('todobox').value;
var futureDate = document.getElementById('future_date').value;
var errorMessage = document.getElementById('error_message');
errorMessage.classList.add("error_text");
// validation for empty textarea
if (getNote === "") {
errorMessage.innerText = 'You must write something in description';
errorMessage.classList.remove("error_text");
document.getElementById('todobox').focus();
return false;
}else if(futureDate === ""){
errorMessage.classList.add("error_text");
errorMessage.innerText = 'You must write date';
errorMessage.classList.remove("error_text");
document.getElementById('future_date').focus();
return false;
}
function validateDate(date) {
var str = date.trim().split("/");
if (str.length == 3) {
str = new Date(str[2], str[1] - 1, str[0], 0, 0, 0);
if (str == 'Invalid Date') return false;
str = [ ("0" + str.getDate()).substr(-2), ("0" + (str.getMonth() + 1)).substr(-2),str.getFullYear()].join("/");
return str === date.trim()
}
return false
}
if (!validateDate(futureDate)) {
errorMessage.innerText = 'You must write correct date'
errorMessage.classList.remove("error_text");
return false;
}
var toDo = {id: getId, toDo: getNote, date: futureDate}
if (localStorage.getItem('todolist') == null){
var to_do_list = [];
to_do_list.push(toDo);
localStorage.setItem('todolist', JSON.stringify(to_do_list));
}
else{
var to_do_list = JSON.parse(localStorage.getItem('todolist'));
to_do_list.push(toDo);
localStorage.setItem('todolist', JSON.stringify(to_do_list));
}
document.getElementById('todolist').reset();
newNote();
}
// save note
function newNote(){
var newNoteList = JSON.parse(localStorage.getItem('todolist'))||[];
noteboard.innerHTML = '';
for(var i = 0; i <newNoteList.length; i++){
var id = newNoteList[i].id;
var toDoText = newNoteList[i].toDo;
var myDate = new Date(id).toLocaleString();
noteboard.innerHTML += '<div class="col-md-2 delete">' + '<span class="remove" onclick="deleteToDo(\''+id+'\')">'+ '<i class="far fa-trash-alt"></i>'+'</span>' +'<div id="text">'+ toDoText +'</div>'+ '<span class="date">'+ myDate +'</span>'+'</div>';
}
}
// delete notes
function deleteToDo(id){
var delete_to_do = JSON.parse(localStorage.getItem('todolist'));
for (var i = 0; i < delete_to_do.length; i++) {
if (delete_to_do[i].id == id){
delete_to_do.splice(i,1);
}
}localStorage.setItem('todolist', JSON.stringify(delete_to_do));
newNote();
}