blend out / blend in table columns

S

sebb86

Hello JavaScript Google Group :)

My english is not the best, so sorry for mistakes.
I try to blend in (show) and blend out (dont show) table columns.
The following link shows a working file.

Link: http://nopaste.info/0271b9b231.html

At the moment, i can blend out and blend in one column but the next
column header is also affected. Thats the fault and i dont know, whats
wrong. It would be very nice, if someone could help me.

Thanks very much and Greetings!!!
 
G

Gregor Kofler

sebb86 meinte:
Hello JavaScript Google Group :)

My english is not the best, so sorry for mistakes.
I try to blend in (show) and blend out (dont show) table columns.
The following link shows a working file.

Link: http://nopaste.info/0271b9b231.html

At the moment, i can blend out and blend in one column but the next
column header is also affected. Thats the fault and i dont know, whats
wrong. It would be very nice, if someone could help me.

Wrong index? With the tds you - correctly - use iNumber - 1, with the
ths you use iNumber.
Thanks very much and Greetings!!!

Get yourself a debugger (I recommend Firebug).

Gregor
 
S

sebb86

Hello,
do you mean, i have to use iNumber-1 in bot cases?

That also dont works correctly :/
 
S

sebb86

With this code, my problem is solved.

Code:
<script type="text/javascript">
function toggleColumn(table, column) {
for (var i = 0; i < table.rows.length; i++){
if (table.rows[i].cells.length > column){
var cell = table.rows[i].cells[column];
cell.style.display = (cell.style.display == "none")? "": "none";
}
}
}
</script>

Code:
<table>
<tr>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 1);">1</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 2);">2</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 3);">3</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 4);">4</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 5);">5</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 6);">6</a></td>
</tr>
</table>

<br><p>

<table id="tab1">
<tr>
<th>[Optionen]</th>
<th>...</th>
...
 
T

Thomas 'PointedEars' Lahn

sebb86 said:
With this code, my problem is solved.

You want to learn to quote, though.

Code:
[/QUOTE]

No Web forum here, only plain text.
[QUOTE]
<script type="text/javascript">
function toggleColumn(table, column) {
for (var i = 0; i < table.rows.length; i++){
if (table.rows[i].cells.length > column){
var cell = table.rows[i].cells[column];
cell.style.display = (cell.style.display == "none")? "": "none";
}
}
}[/QUOTE]

function toggleColumn(table, column)
{
for (var rows = table.rows,
i = rows.length;
i--;)
{
var cells = rows[i].cells;

if (cells.length > column)
{
var cell = cells[column];
cell.style.display = (cell.style.display == "none") ? "" : "none";
}
}
}
[QUOTE]
</script>

<table>
<tr>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 1);">1</a></td>
<td><a
onclick="toggleColumn(document.getElementById('tab1'), 2);">2</a></td>
[...][/QUOTE]

You should either hard-code the element ID or use a variable/property to
store the object reference.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top