-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.html
59 lines (54 loc) · 1.45 KB
/
CRUD.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="txt" placeholder="name">
<button onclick="add()">ADD</button>
<div id="display"></div>
<input type="number" id="index">
<input type="text" id="edit">
<button onclick="editfun()">Edit</button>
</body>
<script>
const arr = [];
function add() {
getValue = document.getElementById("txt")
if(getValue.value == ""){
document.write("please enter data");
}
else{
arr.push(getValue.value);
getValue.value = "";
display();
console.log(arr);
}
}
function display() {
let areaDis = document.getElementById('display')
areaDis.innerHTML = "";
for (i = 0; i < arr.length; i++) {
areaDis.innerHTML += arr[i]+`<button onclick="deletefun(${i})">Delete</button>`+" </br>";
}
}
function deletefun(i){
arr.splice(i,1);
display();
}
function editfun(){
index=0;
index = document.getElementById("index");
let edit= document.getElementById("edit");
if(index.value > arr.length || index.value<=0 ){
document.write("no index found");
}
else{
arr[index.value]=edit.value;
display();
}
}
</script>
</html>