/    Sign up×
Community /Pin to ProfileBookmark

Getting table height

Hi,

I have a web page that is displayed in a pop up window. The content of the page is a simple table (1 row 1 column) with text in it. This is so I can create a red border around the text…i have considered using a div…maybe that will help in this instance….

anyway….the text can vary from 1 line to many lines. I would like the window to resize to fit the text. Currently the pop-up window is set as height=300, width=300. I have tried detecting the height of the table and setting the window height from that but the javascript can’t seem to accept that the table is an object. Here is the basic outline of the body of the document.

<BODY>
<Form id=”Form1″>
<TABLE id =”Table1″>
<tr><td>
Text here
</td></tr>
</TABLE>
</FORM>
</BODY>

I am able to resize the window using resizeTo(x,y) but detecting the height of the table is proving impossible (hmm..probably not impossible…difficult maybe ? ).

I have tried:

tableHeight = document.Form1.Table1.style.height

and

table1 = document.getElementById(“Table1”);
tableHeight = table1.style.height

with no luck. Am i missing something obvious?

Thanks
Guy

PS. I am using IE6

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 13.2005 — tableHeight = table1.offsetHeight;

Since you have no style defined, there is no style.height to be grabbed. Anyway, a table will always follow the sum of the height of all it's inner components
Copy linkTweet thisAlerts:
@iamguysterauthorJul 13.2005 — Ah i see. I will try that.

I understand that the table will conform in height to it's contents..it'a exactly this height I need to detect as it varies depending on what I print out into it and I would like my pop up window to always be just slightly larger than the table.

Cheers

Guy
Copy linkTweet thisAlerts:
@KorJul 13.2005 — offsetHeight will do that job
Copy linkTweet thisAlerts:
@iamguysterauthorJul 14.2005 — That worked beautifully! here's the script I used in case anyone else has a similar question:

table1 = document.getElementById("Table1");

var newHeight = table1.offsetHeight + 60;

window.resizeTo(320, newHeight);

Cheers

G
Copy linkTweet thisAlerts:
@hanshuckebeinDec 03.2008 — ...that did not work with me! The result for the table1 hight was allways 0.

Martin
Copy linkTweet thisAlerts:
@KorDec 04.2008 — show us your code
×

Success!

Help @iamguyster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...