/    Sign up×
Community /Pin to ProfileBookmark

getting control height and widths?

based on code Fang gave in
[url]http://www.webdeveloper.com/forum/showthread.php?postid=433538#poststop[/url]

I am able to get multiple things done during the OnLoad event. However, when I try to access things like the height or width of a control or object on the page, such as a Table or listbox, it doesn’t do anything.
I tried something like
alert(‘the value is ‘ + document.getElementById(“BigTable”).height);

That didn’t do anything. So I’m wondering if after the page loads, how I can
access height and width of things on the page.

After I do this, what I’m hoping to do is change the height (and/or width) of one table, to be exactly the same as another that is on the page.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@cootheadSep 14.2005 — Hi there HockeyFan,

you may find this of interest...
[color=navy]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>get object information</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="Content-Script-Type" content="text/javascript"/>
<meta name="Content-Style-Type" content="text/css"/>
<style type="text/css">
/*<![CDATA[*/
body {
font-family:verdana,arial,helvetica,sans-serif;
font-size:16px;
color:#000;
background-color:#ccc;
}
#foo {
width:324px;
height:200px;
border:3px double #000;
background-color:#fff;
overflow:auto;
margin:20px auto;
}
#blah {
width:648px;
border:1px solid #000;
background-color:#fff;
margin:auto;
}
#foo p,#blah p {
margin:10px;
text-align:justify;
} <br/>
/*//]]&gt;*/
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
function getInfo(obj) {
alert('width= '+obj.offsetWidth+'px, height= ' +obj.offsetHeight+'pxnn'+
'left= '+obj.offsetLeft+'px, top= '+obj.offsetTop+'px');
}
//]]&gt;
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="foo" onclick="getInfo(this)"&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent blandit venenatis purus.
Integer massa libero, vehicula id, consequat sed, tincidunt nec, purus. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti.
Nunc vulputate magna non magna. Aenean lorem eros, adipiscing quis, semper non, dictum a,
nunc. Curabitur ut sem. Pellentesque a est id neque hendrerit ultrices. Donec vulputate tincidunt
turpis. Curabitur dignissim vestibulum nunc. Aliquam felis lorem, ultrices sit amet, convallis a,
accumsan vel, ante. Proin aliquam turpis sed augue. In pellentesque, magna a pulvinar adipiscing,
est orci adipiscing felis, sed laoreet urna magna quis neque. Proin facilisis aliquet urna.
&lt;/p&gt;
&lt;/div&gt;

&lt;div id="blah" onclick="getInfo(this)"&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent blandit venenatis purus.
Integer massa libero, vehicula id, consequat sed, tincidunt nec, purus. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti.
Nunc vulputate magna non magna. Aenean lorem eros, adipiscing quis, semper non, dictum a,
nunc. Curabitur ut sem. Pellentesque a est id neque hendrerit ultrices. Donec vulputate tincidunt
turpis. Curabitur dignissim vestibulum nunc. Aliquam felis lorem, ultrices sit amet, convallis a,
accumsan vel, ante. Proin aliquam turpis sed augue. In pellentesque, magna a pulvinar adipiscing,
est orci adipiscing felis, sed laoreet urna magna quis neque. Proin facilisis aliquet urna.
&lt;/p&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]

..just add....
[color=navy]
onclick="getInfo(this)"
[/color]

...to any element of which you require unformation.

[i]coothead[/i]
Copy linkTweet thisAlerts:
@HockeyFanauthorSep 14.2005 — how do you do it if you don't want to click. You want it done after the page loads.
Copy linkTweet thisAlerts:
@cootheadSep 14.2005 — like this...
[color=navy]&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;title&gt;get object information&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
&lt;meta name="Content-Script-Type" content="text/javascript"/&gt;
&lt;meta name="Content-Style-Type" content="text/css"/&gt;
&lt;style type="text/css"&gt;
/*&lt;![CDATA[*/
body {
font-family:verdana,arial,helvetica,sans-serif;
font-size:16px;
color:#000;
background-color:#ccc;
}
#foo {
width:324px;
height:200px;
border:3px double #000;
background-color:#fff;
overflow:auto;
margin:20px auto;
}
#blah {
width:648px;
border:1px solid #000;
background-color:#fff;
margin:auto;
}
#foo p,#blah p {
margin:10px;
text-align:justify;
} <br/>
/*//]]&gt;*/
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
function getInfo() {
obj=document.getElementById('foo');
obj1=document.getElementById('blah');
alert(' "foo" width= '+obj.offsetWidth+'px, "foo" height= ' +obj.offsetHeight+'pxnn'+
' "foo" left= '+obj.offsetLeft+'px, "foo" top= '+obj.offsetTop+'pxnnand...nn'+
' "blah" width= '+obj1.offsetWidth+'px, "blah" height= ' +obj1.offsetHeight+'pxnn'+
' "blah" left= '+obj1.offsetLeft+'px, "blah" top= '+obj1.offsetTop+'px');
}
//]]&gt;
&lt;/script&gt;

&lt;/head&gt;
&lt;body onload="getInfo()"&gt;

&lt;div id="foo"&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent blandit venenatis purus.
Integer massa libero, vehicula id, consequat sed, tincidunt nec, purus. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti.
Nunc vulputate magna non magna. Aenean lorem eros, adipiscing quis, semper non, dictum a,
nunc. Curabitur ut sem. Pellentesque a est id neque hendrerit ultrices. Donec vulputate tincidunt
turpis. Curabitur dignissim vestibulum nunc. Aliquam felis lorem, ultrices sit amet, convallis a,
accumsan vel, ante. Proin aliquam turpis sed augue. In pellentesque, magna a pulvinar adipiscing,
est orci adipiscing felis, sed laoreet urna magna quis neque. Proin facilisis aliquet urna.
&lt;/p&gt;
&lt;/div&gt;

&lt;div id="blah"&gt;
&lt;p&gt;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent blandit venenatis purus.
Integer massa libero, vehicula id, consequat sed, tincidunt nec, purus. Class aptent taciti
sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse potenti.
Nunc vulputate magna non magna. Aenean lorem eros, adipiscing quis, semper non, dictum a,
nunc. Curabitur ut sem. Pellentesque a est id neque hendrerit ultrices. Donec vulputate tincidunt
turpis. Curabitur dignissim vestibulum nunc. Aliquam felis lorem, ultrices sit amet, convallis a,
accumsan vel, ante. Proin aliquam turpis sed augue. In pellentesque, magna a pulvinar adipiscing,
est orci adipiscing felis, sed laoreet urna magna quis neque. Proin facilisis aliquet urna.
&lt;/p&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]


[i]cooothead[/i]
×

Success!

Help @HockeyFan 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.16,
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,
)...