Skip to content

Instantly share code, notes, and snippets.

@ezesundayeze
Last active April 25, 2017 19:12
Show Gist options
  • Save ezesundayeze/a7b683a7448f8ee53aadd5ffc226a108 to your computer and use it in GitHub Desktop.
Save ezesundayeze/a7b683a7448f8ee53aadd5ffc226a108 to your computer and use it in GitHub Desktop.
function saveTask(e){
 //get form values
var taskName = document.getElementById(“taskName”).value;
var taskDescription = document.getElementById(“taskDescription”).value;
//create an object to store the variables
var tasks = {
name:taskName,
description:taskDescription
}
if(localStroage.getItem(‘tasks’)==null){ 
var task =[]; task.push(tasks);
localStorage.SetItem('task',JSON.stringyfy(task));
}else{
var myTask = localStorage.getItem('task',JSON.parse(task)); myTask.push(task);
// then reset the localStorage
localStorage.setItem('task',JSON.stringify(myTask));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment