Skip to content
Permalink
Browse files
Reset Task Code
  • Loading branch information
aa7401 committed Nov 18, 2019
1 parent 6f3b78d commit 60e920c8fc912e92e095711f6560805ab2ed5b76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
@@ -13,8 +13,8 @@
</head>
<body>
<h1>ToDo List</h1>
<form>
<input name="item" type="text" autofocus />
<form onkeydown="return event.key != 'Enter';">
<input name="item" type="text" autofocus />
<input type="submit" value="add" />
<table></table>
<ol></ol>
@@ -1,12 +1,17 @@

'use strict'

let tableVisible = false

const itemCol = 0
const qtyCol = 1
const actCol = 2

document.addEventListener('DOMContentLoaded', () => {
console.log('page loaded')
// document.querySelectorAll('td').onclick = deleteRow
document.querySelector('input[name="item"]').focus()
document.querySelectorAll('input').forEach( elem => elem.onkeyup = addText )
document.querySelector('form').onsubmit = addItem
// document.querySelector('table').onclick = deleteRow
document.querySelector('table').onclick = deleteRow
})

@@ -25,17 +30,20 @@ function addItem() {
itemField.focus()
if(item.length) addNode(item)
return false // prevents the form from submitting

}

function clearInput() {
document.querySelector('input[name="item"]').value = ''
document.querySelector('input[name="item"]').focus()
}

function addNode(item) {
// const node = document.createElement('li') // Create a <li> node
// const textnode = document.createTextNode(item) // Create a text node
// node.appendChild(textnode) // Append the text to <li>
// document.querySelector('ol').appendChild(node)
function addNode(item, qty) {
const table = document.querySelector('table')
const row = table.insertRow(-1)
row.insertCell(0).innerHTML = item
row.insertCell(1).innerHTML = '<a href="#">delete</a>'
clearInput()
}

function deleteRow(e) {
@@ -13,5 +13,3 @@ td {
margin: 0;
padding: 5px;
}


0 comments on commit 60e920c

Please sign in to comment.