7 function genName(prefix) {
8 return
"X" + count++ +
"\n";
12 var rgInput = document.getElementsByTagName(
"INPUT")[
0];
13 var rgIndex = rgInput.value;
14 var rowInput = document.getElementsByTagName(
"INPUT")[
1];
15 var rowIndex = rowInput.value;
16 var colInput = document.getElementsByTagName(
"INPUT")[
2];
17 var colIndex = colInput.value;
18 var rowSpanInput = document.getElementsByTagName(
"INPUT")[
3];
19 var rowSpan = rowSpanInput.value;
20 var colSpanInput = document.getElementsByTagName(
"INPUT")[
4];
21 var colSpan = colSpanInput.value;
22 var select = document.getElementsByTagName(
"SELECT")[
0];
23 var actionIndex = select.selectedIndex;
25 var table = document.getElementsByTagName(
"TABLE")[
0];
26 var tbodies = table.tBodies;
27 var tbody = tbodies.item(rgIndex);
30 if (
0 == actionIndex) {
31 var rows = tbody.rows;
32 var row = rows.item(rowIndex);
33 //appendCell(rowIndex, rowSpan, colSpan);
34 appendCell(row,
1,
1);
36 else if (
1 == actionIndex) {
37 var rows = tbody.rows;
38 var row = rows.item(rowIndex);
39 //insertCell(rowIndex, colIndex, rowSpan, colSpan);
40 insertCell(row, colIndex,
1,
1);
42 else if (
2 == actionIndex) {
43 var rows = tbody.rows;
44 var row = rows.item(rowIndex);
45 deleteCell(row, colIndex);
47 else if (
3 == actionIndex) {
50 else if (
4 == actionIndex) {
51 insertRow(tbody, rowIndex);
53 else if (
5 == actionIndex) {
54 deleteRow(tbody, rowIndex);
56 else if (
6 == actionIndex) {
57 buildTable(rowIndex, colIndex);
61 function appendCellx(aRowIndex, aRowSpan, aColSpan) {
62 var row = document.getElementsByTagName(
"TR")[aRowIndex];
63 var cell = document.createElement(
"TD", null);
65 cell.colSpan = aColSpan;
66 var text = document.createTextNode(genName());
67 cell.appendChild(text);
68 row.appendChild(cell);
71 function insertCell(aRowIndex, aColIndex, aRowSpan, aColSpan) {
72 dump(aRowSpan); dump(aColSpan);
73 var row = document.getElementsByTagName(
"TR")[aRowIndex];
74 //var refCell = document.getElementsByTagName(
"TD")[
0];
75 var cells = row.cells;
76 var refCell = cells.item(aColIndex);
77 var newCell = document.createElement(
"TD", null);
78 newCell.rowSpan = aRowSpan;
79 newCell.colSpan = aColSpan;
80 var text = document.createTextNode(genName());
81 newCell.appendChild(text);
82 row.insertBefore(newCell, refCell);
83 //dump(
"SCRIPT: inserted CELL as first cell in first row\n");
86 function deleteCell(aRowIndex, aColIndex) {
87 var row = document.getElementsByTagName(
"TR")[aRowIndex];
88 row.deleteCell(aColIndex);
91 function appendRow(aRowGroupIndex) {
92 var rg = document.getElementsByTagName(
"TBODY")[aRowGroupIndex];
93 var row = document.createElement(
"TR", null);
95 appendCell(row.rowIndex,
1,
1);
98 function insertRow(aRowGroupIndex, aRowIndex) {
99 var rg = document.getElementsByTagName(
"TBODY")[aRowGroupIndex];
100 var refRow = document.getElementsByTagName(
"TR")[aRowIndex];
101 var row = document.createElement(
"TR", null);
102 rg.insertBefore(row, refRow);
105 function buildTable(aNumRows, aNumCols) {
106 var table = document.getElementsByTagName(
"TABLE")[
0];
107 for (rowX =
0; rowX < aNumRows; rowX++) {
108 var row = document.createElement(
"TR", null);
109 for (colX =
0; colX < aNumCols; colX++) {
110 var cell = document.createElement(
"TD", null);
111 var text = document.createTextNode(genName());
112 cell.appendChild(text);
113 row.appendChild(cell);
115 table.appendChild(row);
124 <option>append cell
</option>
125 <option>insert cell
</option>
126 <option>delete cell
</option>
127 <option>append row
</option>
128 <option>insert row
</option>
129 <option>delete row
</option>
130 <option>build table
</option>
133 <input type=text size=
5 value=
0>
135 <input type=text size=
5 value=
0>
137 <input type=text size=
5 value=
0>
139 <input type=text size=
5 value=
1>
141 <input type=text size=
5 value=
1>
143 <INPUT TYPE=
"button" NAME=
"doIt" VALUE=
"Do It" onClick=
"doIt()" width=
100>
146 <table bgcolor=orange border
>
152 <td>c21
</td><td>c22
</td>