T
Tuxedo
I'm attempting to stick together a procedure that determines the number of
cells in all rows of tables, based on a user defined variable of columns.
The variable needs to determine where the </tr>'s and <tr>'s are inserted.
Like for example:
var row_length = 3; // number of cells in all rows, i.e. columns
var gallery = new Array();{
gallery[0] = "entry 1";
gallery[1] = "entry 2";
gallery[2] = "entry 3";
gallery[3] = "entry 4";
gallery[4] = "entry 5";
gallery[5] = "entry 6";
gallery[6] = "entry 7";
gallery[7] = "entry 8";
gallery[8] = "entry 9";
gallery[9] = "entry 10";
gallery[10] = "entry 11";
}
var insert_tr = 1;
document.write('<table border=1><tr>');
for (i = 0; i < gallery.length; i++, insert_tr++){
document.write('<td>'+gallery + '</td>')
if (insert_tr == row_length) {
document.write('</tr><tr>')
insert_tr = 0;
}
}
document.write('</tr></table>');
Although the above will display a 3-column table with all items within, it
generates an incorrect html structure, with the last row having a missing
cell:
<table><tr>
<td>entry 1</td>
<td>entry 2</td>
<td>entry 3</td>
</tr><tr>
<td>entry 4</td>
<td>entry 5</td>
<td>entry 6</td>
</tr><tr>
<td>entry 7</td>
<td>entry 8</td>
<td>entry 9</td>
</tr><tr>
<td>entry 10</td>
<td>entry 11</td>
</tr></table>
Or for example, if the variable at the top is set to "row_length = 11" then
there will be an empty row at the end of the table, as follows:
<table><tr>
<td>entry 1</td>
<td>entry 2</td>
<td>entry 3</td>
<td>entry 4</td>
<td>entry 5</td>
<td>entry 6</td>
<td>entry 7</td>
<td>entry 8</td>
<td>entry 9</td>
<td>entry 10</td>
<td>entry 11</td>
</tr><tr>
</tr></table>
Again, it display's, but not correctly.
Does anyone have a better procedure for generating even tables? One which
can for example add empty cells according to the number of missing cells,
if any.
It needs to be generic in the sense that it should work with any number of
predetermined array entries, while the number of rows, i.e. row_length, may
differ at runtime depending on the variable at the top.
There will never be any spanning, as in rowspan or colspan. If there are 2
cells missing at the end, there could simply be 2 cells added with
inside each one.
The above above code truly sucks!
Any better examples would be greatly appreciated!
cells in all rows of tables, based on a user defined variable of columns.
The variable needs to determine where the </tr>'s and <tr>'s are inserted.
Like for example:
var row_length = 3; // number of cells in all rows, i.e. columns
var gallery = new Array();{
gallery[0] = "entry 1";
gallery[1] = "entry 2";
gallery[2] = "entry 3";
gallery[3] = "entry 4";
gallery[4] = "entry 5";
gallery[5] = "entry 6";
gallery[6] = "entry 7";
gallery[7] = "entry 8";
gallery[8] = "entry 9";
gallery[9] = "entry 10";
gallery[10] = "entry 11";
}
var insert_tr = 1;
document.write('<table border=1><tr>');
for (i = 0; i < gallery.length; i++, insert_tr++){
document.write('<td>'+gallery + '</td>')
if (insert_tr == row_length) {
document.write('</tr><tr>')
insert_tr = 0;
}
}
document.write('</tr></table>');
Although the above will display a 3-column table with all items within, it
generates an incorrect html structure, with the last row having a missing
cell:
<table><tr>
<td>entry 1</td>
<td>entry 2</td>
<td>entry 3</td>
</tr><tr>
<td>entry 4</td>
<td>entry 5</td>
<td>entry 6</td>
</tr><tr>
<td>entry 7</td>
<td>entry 8</td>
<td>entry 9</td>
</tr><tr>
<td>entry 10</td>
<td>entry 11</td>
</tr></table>
Or for example, if the variable at the top is set to "row_length = 11" then
there will be an empty row at the end of the table, as follows:
<table><tr>
<td>entry 1</td>
<td>entry 2</td>
<td>entry 3</td>
<td>entry 4</td>
<td>entry 5</td>
<td>entry 6</td>
<td>entry 7</td>
<td>entry 8</td>
<td>entry 9</td>
<td>entry 10</td>
<td>entry 11</td>
</tr><tr>
</tr></table>
Again, it display's, but not correctly.
Does anyone have a better procedure for generating even tables? One which
can for example add empty cells according to the number of missing cells,
if any.
It needs to be generic in the sense that it should work with any number of
predetermined array entries, while the number of rows, i.e. row_length, may
differ at runtime depending on the variable at the top.
There will never be any spanning, as in rowspan or colspan. If there are 2
cells missing at the end, there could simply be 2 cells added with
inside each one.
The above above code truly sucks!
Any better examples would be greatly appreciated!