-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrud Table.js
More file actions
60 lines (51 loc) · 1.49 KB
/
Crud Table.js
File metadata and controls
60 lines (51 loc) · 1.49 KB
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
let superheros = [
{
"name" : "Parth",
"age": 21,
"city" : "Nashik",
"salary" : 20000
}
];
function display(superarray) {
let tabledata = "";
superarray.forEach(function (superhero,index) {
let currow = `<tr>
<td>${index+1}</td>
<td>${superhero.name}</td>
<td>${superhero.age}</td>
<td>${superhero.city}</td>
<td>${superhero.salary}</td>
<td><button id="btn2" onClick="deletesupr(${index})">Delete</button></td>
</tr>`;
tabledata += currow;
index +1
});
document.getElementById("tdata").innerHTML = tabledata;
}
display(superheros)
function addSuperHero(e){
e.preventDefault();
let superhero={}
let name = document.getElementById("name").value;
let age = document.getElementById("age").value;
let city = document.getElementById("city").value;
let salary = document.getElementById("salary").value;
superhero.name=name;
superhero.age=Number(age);
superhero.city=city;
superhero.salary=salary;
superheros.push(superhero);
display(superheros)
document.getElementById("form").reset();
}
function Searchf(){
let SearchVlaue=document.getElementById("search").value;
let Sear = superheros.filter(function(superhero){
return superhero.name.toUpperCase().indexOf(SearchVlaue.toUpperCase())!=-1 || superhero.city.toUpperCase().indexOf(SearchVlaue.toUpperCase())!=-1
});
display(Sear);
}
function deletesupr(index){
superheros.splice(index,1);
display(superheros)
}