-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion4.html
More file actions
76 lines (67 loc) · 2.35 KB
/
Copy pathQuestion4.html
File metadata and controls
76 lines (67 loc) · 2.35 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload = function ()
{
var customers = new Array();
//Add the data rows.
for (var i = 0; i < customers.length; i++) {
AddRow(customers[i][0], customers[i][1]);
}
};
function Add() {
var txtName = document.getElementById("txtName");
var txtCountry = document.getElementById("txtCountry");
AddRow(txtName.value, txtCountry.value);
txtName.value = "";
txtCountry.value = "";
};
function Remove(button) {
//Determine the reference of the Row using the Button.
var row = button.parentNode.parentNode;
var name = row.getElementsByTagName("TD")[0].innerHTML;
if (confirm("Do you want to delete: " + name)) {
//Get the reference of the Table.
var table = document.getElementById("tblCustomers");
//Delete the Table row using it's Index.
table.deleteRow(row.rowIndex);
}
};
function AddRow(name, country) {
//Get the reference of the Table's TBODY element.
var tBody = document.getElementById("tblCustomers").getElementsByTagName("TBODY")[0];
//Add Row.
row = tBody.insertRow(-1);
//Add Name cell.
var cell = row.insertCell(-1);
cell.innerHTML = name;
//Add Country cell.
cell = row.insertCell(-1);
cell.innerHTML = country;
//Add Button cell.
cell = row.insertCell(-1);
var btnRemove = document.createElement("INPUT");
btnRemove.type = "button";
btnRemove.value = "Remove";
btnRemove.setAttribute("onclick", "Remove(this);");
cell.appendChild(btnRemove);
}
</script>
<table id="tblCustomers" cellpadding="0" cellspacing="0" border="1">
<thead>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td><input type="text" id="txtName" /></td>
<td><input type="text" id="txtCountry" /></td>
<td><input type="button" onclick="Add()" value="Add" /></td>
</tr>
</tfoot>
</table>
</body>
</html>