-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
84 lines (78 loc) · 3.11 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body class="">
<div class="container">
<div class=" card p-5">
<div class="left-inputCol" style="text-align: center;">
<input type="text" placeholder="Event/Activity" class="form-control mb-3" id="eventInput">
<input type="text" placeholder="Description" class="form-control mb-3" id="eventDesc"1>
<input type="button" value="CREATE EVENT" class="btn bg-primary" style="color: white;" id="btn">
</div>
</div>
<div id="resultField" class="mt-5">
<table class="table table-striped table-dark">
<thead class="thead-light">
<tr>
<th >S/N</th>
<th>Event</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tBody">
</tbody>
</table>
</div>
</div>
<script>
var newEvId,newDesId, eventInput, descInput;
var btn = document.getElementById('btn');
var cache = [];
var b = 1;
btn.addEventListener('click', toDo);
//Creating a function that gets input values and store them in an array as object-------
function getValue(){
eventInput = document.getElementById("eventInput").value;
descInput = document.getElementById("eventDesc").value;
var obj = {
event : eventInput,
description : descInput
}
cache.push(obj)
}
//--------------------------------------------------------------------------------------
//creating a function that creates a table row with value---------------------------------------
function crtRow(){
var tBody = document.getElementById("tBody");
tBody.innerHTML="";
cache.forEach (function (ram,i){
tBody.innerHTML +=
`<tr>
<td><div id="SN"><span>${i+1}</span></div></td>
<td><div><p id="${newEvId}">${ram.event}</p</div></td>
<td><div ><p id="${newDesId}">${ram.description}</p</div></td>
<td><input type="button" value="DEL" class="btn bg-danger " onClick= del(${i})></td>
</tr>`;
})
}
//----------------------------------------------------------------------------------------------------
//creating a function that executes the TODO
function toDo (){
getValue();
crtRow();
}
function del(anc){
cache.splice(anc,1);
console.log(cache);
crtRow();
}
</script>
</body>
</html>