Page 1 of 1
hide columns in dynamic table
Posted: Tue Oct 05, 2004 2:19 pm
by colmtourque
I have a table created such: (I've simplified the code)
Code: Select all
$result1= mysql_query("SELECT IDNumber AS r1IDNumber, FROM wanuserinformation",$db) or die("Query failed : " . mysql_error()
if ($myrow1 = mysql_fetch_array($result1))
{
?>
<table border=2 bordercolor=red>
<tr><td>ID Number</td>
<?php
$count=1;
do
{
$count=$count+1;
?>
<td id="pc"><input type="text" name="pcnotes<?php echo $count; ?>"></td>
<?php
echo "</tr></table>";
}while ($myrow1 = mysql_fetch_array($result1));
I know how to use javascript and css to change a static table. But how would you go about changing a table created using code. Since the id's will change row to row.
Posted: Tue Oct 05, 2004 2:25 pm
by feyd
build a pattern out of the id's.. like pcnotes_1_1 for the upper left (first row, first column) cell.. and so on..then just run ~blindly through the id's until you hit an undefined id.
javascript skills arn't that good
Posted: Tue Oct 05, 2004 2:43 pm
by colmtourque
For instance I know I can use this:
Code: Select all
<script>
//resize table
function shrink (whichID)
{
document.getElementById(whichID).width = 1;
}
</script>
<body>
<a href="javascript:shrink('test')">shrink</a>
<table width="100" border="2" bgcolor="#00FF00">
<tr>
<td id=test width=75>
Test
</td>
</tr></table>
</body>
To make that table have one cell shrink, but when I add a second cell I would then have to have a second function for it. So not sure how to go about, running through the code to get that. I am aware roughly that you can assign a class and run through and grab id's but not sure how.
feyd | post code in the proper format please
Posted: Tue Oct 05, 2004 2:58 pm
by feyd
no class needed..
untested
Code: Select all
function getElem( id )
{
return document.getElementById ? document.getElementById( id ) : document.allї id ];
}
function hideColumn( column )
{
var obj;
var c = 0;
var col = parseInt(column);
while(obj = getElem( 'pcnotes_' + (++c) + '_' + col)) obj.style.display = 'none';
}
hideColumn( 2 );
OK tried a modification
Posted: Tue Oct 05, 2004 4:11 pm
by colmtourque
So where am I confused?
Code: Select all
<script>
//resize table
function getElem( id )
{
return document.getElementById ? document.getElementById( id ) : document.allї id ];
}
function hideColumn( column )
{
var obj;
var c = 0;
var col = parseInt(column);
while(obj = getElem( 'pcnotes_' + (++c) + '_' + col)) obj.type = 'hidden';
}
</script>
<body>
<a href="javascript:hideColumn()">shrink</a>
<table width="100" border="2">
<tr>
<td>
<input type=text name=pcnotes1>
</td>
</tr>
<tr>
<td>
<input type=text name=pcnotes2>
</td>
</tr>
</table>
</body>
OH, I also tried using yours first:
Code: Select all
<script>
//resize table
function getElem( id )
{
return document.getElementById ? document.getElementById( id ) : document.allї id ];
}
function hideColumn( column )
{
var obj;
var c = 0;
var col = parseInt(column);
while(obj = getElem( 'pcnotes_' + (++c) + '_' + col)) obj.display = 'none';
}
</script>
<body>
<a href="javascript:hideColumn()">shrink</a>
<table width="100" border="2">
<tr>
<td id=pcnotes1>
test1
</td>
</tr>
<tr>
<td id=pcnotes2>
test2
</td>
</tr>
</table>
</body>
Posted: Tue Oct 05, 2004 4:19 pm
by feyd
Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
did you even notice the id names mine uses?