document.write() line being ignored..

M

maya

<table> tag is being ignored here.. why is this..


<div id="img1">

<script type="text/javascript" language="JavaScript">
var cw = document.body.clientWidth;
var ch = document.body.clientHeight;
document.write("<table border=1 cellpadding=0
cellspacing=0 width=100% height=" + ch-80 + ">");
</script>

<tr><td height=80 colspan=2>&nbsp;</td></tr>
<tr><td width=135>&nbsp;</td><td align=center>
<img src="images/img1.jpg" width="718" height="480" alt="">
</td></tr></table>

</div>


thank you...
 
R

Randy Webb

maya said the following on 8/1/2006 10:56 PM:
<table> tag is being ignored here.. why is this..

Because it doesn't get written as you think it does.
<div id="img1">

<script type="text/javascript" language="JavaScript">
var cw = document.body.clientWidth;
var ch = document.body.clientHeight;
document.write("<table border=1 cellpadding=0
cellspacing=0 width=100% height=" + ch-80 + ">");

alert(ch);//gives 0 so how can a table have a width of -80?

The reason it gives me 0 is at the time the table is being written, the
body has not content so its height is - 0.

Change it to height=100px and watch your table.....
 
M

maya

Randy said:
maya said the following on 8/1/2006 10:56 PM:

Because it doesn't get written as you think it does.


alert(ch);//gives 0 so how can a table have a width of -80?

The reason it gives me 0 is at the time the table is being written, the
body has not content so its height is - 0.

Change it to height=100px and watch your table.....

thank you Randy... so by the time that JS code (inside <body>) is
executing JS still doesn't know what the dimensions are of
document.body.clientHeight.... wild..

so I tried this:

window.onload=document.write("<table border=1 cellpadding=0
cellspacing=0 width=100% height=" + ch-80 + ">");

but it still doesn't work... how can I then say ok, run this code ONLY
once you know how tall browser window is....:)

thanks again..
 
G

Georgi Naumov

Hint:
var cw = document.body.clientWidth +"px";
var ch = document.body.clientHeight +"px";
Did you try this way ?
maya напиÑа:
 
M

maya

Georgi said:
Hint:
var cw = document.body.clientWidth +"px";
var ch = document.body.clientHeight +"px";
Did you try this way ?

yes, I did, Georgi, thank you.. (actually not sure you need "px" in
there because for table height in html you don't have to specify px..
error was of different nature..

I actually have two of these,
<script type="text/javascript" language="JavaScript">
var cw = document.body.clientWidth;
var ch = document.body.clientHeight-100;
document.write('<div id="thumbs" style="height:' + ch + ';">');
/* rest of styles for this div in header, good to know you can split
css code like that, like this you put only props whose values are vars
in here....:)
</script>

<script type="text/javascript" language="JavaScript">
var cw = document.body.clientWidth;
var ch = document.body.clientHeight-80;
document.write('<table border=0 cellpadding=0 cellspacing=0 width="100%"
height=' + ch + '>');
</script>

the first one never gave me hard time, only the second one did because
I had it only once instead of putting it into each div...:) and this
one is of divs that show up and disappear dynamically..) thank you very
much...

thank you again.......

-m
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top