-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManageTodos.html
40 lines (37 loc) · 1.09 KB
/
ManageTodos.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE HTML>
<html>
<body>
<form onsubmit="return false">
Add ToDo:
<input type="text" id="NewTodoItemTextField"
onkeydown="checkKey(event)">
<input type="button" id="AddButton" value="Add To List"
onClick="addTodoItemToList()"><br>
</form>
<ul id="todolist">
</ul>
</body>
</html>
<script type="text/javaScript">
function checkKey(event){
if(event.keyCode == 13){
addTodoItemToList();
}
}
function addTodoItemToList(){
var TodoText = document.getElementById("NewTodoItemTextField").value;
if(TodoText.length>0){
document.getElementById("NewTodoItemTextField").value = "";
var ToDoItemList = document.getElementById("todolist");
var newListItem = document.createElement("li");
var newListItemText = document.createTextNode(TodoText);
newListItem.onclick = removeItemFromList;
newListItem.appendChild(newListItemText);
ToDoItemList.insertBefore(newListItem,ToDoItemList.childNodes[0]);
}
}
function removeItemFromList(){
var ToDoItemList = document.getElementById("todolist");
ToDoItemList.removeChild(this);
}
</script>