LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2007, 03:58 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Is there a way to find the size of an html table (javascript?)


Is there a way to find the size of a table?

Say, for instance, you have this code:
Code:
<table>
 <tr>
  <td>
   hi
  </td>
 </tr>
</table>
.. that table will be smaller than this table:

Code:
<table>
 <tr>
  <td>
   hello_world!!
  </td>
 </tr>
</table>
... so is there a way to find the size of the table after the fact?
 
Old 10-03-2007, 04:14 PM   #2
devn
Member
 
Registered: Mar 2007
Location: Bangladesh
Distribution: Suse, Solaris
Posts: 40

Rep: Reputation: 15
How are you determining the size of the table? by counting no. of trs and tds?
Javascript has a method called getParent(). I guess you could refer to that if it solves your problem.
 
Old 10-03-2007, 04:24 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by devn View Post
How are you determining the size of the table? by counting no. of trs and tds?
Javascript has a method called getParent(). I guess you could refer to that if it solves your problem.
By 'size' I mean pixels.

In the end, what I'm trying to do is wrap an iframe around a table, but I don't want horizontal scrolling & don't want any of the table to be outside of the iframe, so I need to know how big the table will be. Sometimes these tables get quite large & sometimes there are quite small, so I don't want to just pick a size & go with it - needs to be dynamic.

To go even one step further, what I'm really trying to do is make it so that you can see the first row of each column at all times (where the title of the column goes). My idea was to put that first row in an iframe, then the rest of the table in a vertical scrolling iframe just below it.

Any other suggestions are welcome... dynamic resizing of iframes? fancy css to hold the top row? ...or someone can just post how to figure the table size in pixels.

Last edited by BrianK; 10-03-2007 at 04:26 PM.
 
Old 10-04-2007, 08:29 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I had to smile when I saw your question... not that it is a stupid question, but during my own project I found it next to impossible to determine the width of the table.

Point is, the algorithm to determine the table and cell width is very complicated. And once you figured it out, you'll notice that different browsers have interpreted and implemented the algorithm completely different. Specifying column widths in <td> or <col> tags is nice, but it is overruled by the contents of the cells. The algorithm is described on the w3c.org web site.

I have an application using fixed font sizes as specified using CSS, and still my table look completely different in IE, Opera, Firefox and Epiphany. Even from one version to the other it is different...

If you use an iframe, at least *that* width is fixed.

My best results so far I had by:

- Specifying a width of 100% in the <table> tag so the table fills the iframe (in my case I used CSS boxes)

- Specifying the column width using the CSS width specifier, like:
Code:
<td align="center" valign="center">
<span class="time1" style="text-align : center; width: 55px;">
   Your text goes here
</span>
</td>
Now I am sure that the text width is not more than 55 pix, if it gets larger, it will not expand the column size, but wrap in the span.

- After you set an exact size for all columns in this way, allow one column to expand and contract freely to adapt to browser differences. You can minimize this effect by making your frame width slightly larger than the sum of all widths. Be sure to add cell padding and border widths to all cells.

This is what gave me the most satisfying solution. Beware though that if you have just one cell without the <span> tag specifying the width, and the text is larger than the column width, your carefully designed table *will* expand at that column.

BTW, the align specifiers in the <td> tag specify how the span is aligned in the cell, but how not the text is aligned. And another nice thing to know, if your cell width becomes less than the span width (for example you aggregate span widths are more than the table width), the alignment within the span is spoiled. That is, in some browsers, not in all.


jlinkels
 
Old 10-04-2007, 10:03 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by jlinkels View Post
I had to smile when I saw your question...
jlinkels
... interesting. Sounds a little np.

I've gotten around this problem by just making the frame 100% wide & have one scroll bar control two frames... This way at least when the user scrolls, they see the same thing in both frames. A single browser scroll bar would have been better (with two appropriately sized, sometimes giant frames), but... such is life.

Thanks for the response. Very helpful.
 
Old 10-05-2007, 04:02 PM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by BrianK View Post
Sounds a little np.
np?

jlinkels
 
Old 10-05-2007, 07:10 PM   #7
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by jlinkels View Post
np?

jlinkels
poorly used (by me), though proper, complexity term wiki.

I've always taken it to mean solvable, but can take a long time and involve many, many steps... though once solved can be replicated in short order.
 
Old 10-06-2007, 05:03 PM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Aaaaarrrrrrghhhhh... I didn't even know that those theories existed. Nice to learn something new once in a while.

But ah.. yes, the table size problem might be an example of that.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript & HTML Tux-O-Matic Programming 1 12-07-2006 05:32 PM
JavaScript: Want to get the amount of html 'names'. RHLinuxGUY Programming 1 12-06-2006 01:52 PM
Html Javascript help apt Programming 3 03-20-2005 11:46 PM
changing an HTML table with javascript eantoranz Programming 2 10-29-2004 12:21 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration