Skip to content

Instantly share code, notes, and snippets.

@drteresavasquez
Created June 27, 2023 20:48
Show Gist options
  • Save drteresavasquez/0fff67746bf34f28ee45e2bd0d6cf67e to your computer and use it in GitHub Desktop.
Save drteresavasquez/0fff67746bf34f28ee45e2bd0d6cf67e to your computer and use it in GitHub Desktop.
document.querySelctor('form').addEventListener('submit', (e) => {
e.preventDefault(); // this prevents the form from reloading on submit
console.log("submitted")
// 1. grab the value from the form
const name = document.querySelector("#name").value;
// 2. create a new object with it
const newObj = {
name,
complete: false,
id: todoArray.length + 1,
}
// 3. push it to the array
todoArray.push(newObject);
// 4. repaint the DOM
todosOnDom();
// 5. reset the form
document.querySelctor('form').reset()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment