Click to See Complete Forum and Search --> : Adjusting Width of two tables


ukrwq311
03-27-2003, 03:07 AM
Hi all,

I'm trying to programmaically compute the width of the column of a table from those of nother table, like :

<SCRIPT ...>
document.all['col1'].width=document.all['colT1'].width;
document.all['col2'].width=document.all['colT2'].width;
</SCRIPT>

where

<BODY ..>
<DIV ....>
<TABLE ... id='header'>
<tr>
<td id='col1'>
bla bla
</td>
<td id='col2'>
hello world
</td>
</tr>
</table>
</DIV>

<TABLE ... id='main'>
<tr>
<td id='colT1'>
bla bla
</td>
<td id='colT2'>
hello world
</td>
</tr>
</table>

But I cant make the two tables columns match. Does anyone know why?

Thanks in advance.

khalidali63
03-27-2003, 07:45 AM
Originally posted by ukrwq311
Hi all,
.....document.all['col1'].width=document.all['colT1'].width;
..........

HTML element td does not have an attribute width.Therefore you can not get its value.It might work in older versions of IE,but I dont even eant to go there

:D

To your problem.You will have to use style properties such as

<td id='col1' style="width:10pt;">
bla bla
</td>

and

<td id='colT1' style="width:20pt;">
bla bla
</td>

And then use the code you have with this bit of change

document.all['col1'].width=document.all['colT1'].width;

should be

document.all['col1'].style.width=document.all['colT1'].style.width;

Or better yet make it cross browser using W3C standard compliant code

document.getElementById('col1').style.width=document.getElementById('colT1').style.width;
document.getElementById('col2').style.width=document.getElementById('colT1').style.width

I hope this helps

Cheers

Khalid