-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
97 lines (88 loc) · 4.52 KB
/
script.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
var indexNum,
table = document.getElementById("list");
// add Row
function submitData()
{
// get the table by id
// create a new row and cells
// get value from input text
// set the values into row cell's
var newRow = table.insertRow(table.length),
cell1 = newRow.insertCell(0),
cell2 = newRow.insertCell(1),
cell3 = newRow.insertCell(2),
cell4 = newRow.insertCell(3),
cell5 = newRow.insertCell(4),
cell6 = newRow.insertCell(5),
FirstName = document.getElementById("FirstName").value,
LastName = document.getElementById("LastName").value,
Location = document.getElementById("Location").value,
Occupation = document.getElementById("Occupation").value,
Amountneeded = document.getElementById("Amountneeded").value,
Interestrate = document.getElementById("Interestrate").value;
cell1.innerHTML = FirstName;
cell2.innerHTML = LastName;
cell3.innerHTML = Location;
cell4.innerHTML = Occupation;
cell5.innerHTML = Amountneeded;
cell6.innerHTML = Interestrate;
resetinputs();
// call the function to set the event to the new row
rowSelected();
}
// display selected row data into input text
function rowSelected()
{
for(var i = 1; i < table.rows.length; i++)
{
table.rows[i].onclick = function()
{
// get the seected row index
indexNum = this.rowIndex;
document.getElementById("FirstName").value = this.cells[0].innerHTML;
document.getElementById("LastName").value = this.cells[1].innerHTML;
document.getElementById("Location").value = this.cells[2].innerHTML;
document.getElementById("Occupation").value = this.cells[3].innerHTML;
document.getElementById("Amountneeded").value = this.cells[4].innerHTML;
document.getElementById("Interestrate").value = this.cells[5].innerHTML;
};
}
}
rowSelected();
function editData()
{
var FirstName = document.getElementById("FirstName").value,
LastName = document.getElementById("LastName").value,
Location = document.getElementById("Location").value,
Occupation = document.getElementById("Occupation").value,
Amountneeded = document.getElementById("Amountneeded").value,
Interestrate = document.getElementById("Interestrate").value;
table.rows[indexNum].cells[0].innerHTML = FirstName;
table.rows[indexNum].cells[1].innerHTML = LastName;
table.rows[indexNum].cells[2].innerHTML = Location;
table.rows[indexNum].cells[3].innerHTML = Occupation;
table.rows[indexNum].cells[4].innerHTML = Amountneeded;
table.rows[indexNum].cells[5].innerHTML = Interestrate;
resetinputs();
}
function deletData()
{
table.deleteRow(indexNum);
document.getElementById("FirstName").value = "";
document.getElementById("LastName").value = "";
document.getElementById("Location").value = "";
document.getElementById("Occupation").value = "";
document.getElementById("Amountneeded").value = "";
document.getElementById("Interestrate").value = "";
}
function refresh(){
location.reload();
}
function resetinputs(){
document.getElementById("FirstName").value = "";
document.getElementById("LastName").value = "";
document.getElementById("Location").value = "";
document.getElementById("Occupation").value = "";
document.getElementById("Amountneeded").value = "";
document.getElementById("Interestrate").value = "";
}