Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

size of a cell.

Status
Not open for further replies.

vtatta

Programmer
Mar 21, 2005
6
US
hi,
I am creting a flash image in a <td>. The width and height of the td is not specified since my flash image has a size and it is rendered in that cell with its specified dimension. Flash resizes itself when the browser size is changed (which is quite natural and is intended to work that way). But the same flash image is not occupying the complete cell. It leaves out 5 to 10 mm on all the sides of the <td>. Depending on the number of images I divide the page into different cells say for example there are 4 images and I want to arrange them in 2 rows, the first row has 2 images in 2 <td>'s and the same with the second row.
Except for there is another issue. The whole page is not occupied by these <tr>'s which will have flash images. I mean there is some more information and I dont know how much space that information occupies. Here is an example dipiction.
say this is an html page divided into 3 sections top is the heading left is the table of contents and the middle piece is the place which gets divided into cells.

---------------
|------------- |
| | flash |
| | images |
| | area |
---|------------
The area which is marked as flash image area can be divided as I intend to. But I do not know whatz the size of other information around it. This is the reason why I cannot get the flash image occupy the whole cell. Is there any way that I can get the cell size as interpreted by the DOM? I have a way to redraw the flash (I mean the page is processed twice). And so the first time I can get the size of the cell in which the flash has to be drawn and set the size the second time.

By the way I tried to set the size of <td> this obviously does not work.

regards.

 
Try using offsetHeight and offsetWidth:
Code:
<script language=javascript>
function findSize(obj1, obj2) {
   alert("First cell:\n\nWidth - " + obj1.offsetWidth + "\nHeight - " + obj1.offsetHeight + "\n\nSecond cell:\n\nWidth - " + obj2.offsetWidth + "\nHeight - " + obj2.offsetHeight)
}
</script>
<body>
<form name=blahForm>
<table border=1>
  <tr>
    <td id=td1>blahblahblah</td>
    <td id=td2>second td</td>
  </tr>
</table>
<br>
<input type=button value='click me' onclick='findSize(document.getElementById("td1"), document.getElementById("td2"))'>
</form>
</body>

-kaht

Do the chickens have large talons?
 
thanks kaht, I tried the way you suggested but with no avail. I do not have the luxury to get the ht and wth with the click of a link rather I have a servlet thats called twice when page tries to render a cell. The first time the cell is rendered I try to get the offsetWidth and height but the values that I get back are 0.

regards.
 

Are you waiting until the page has fully loaded before calling your routine?

Dan


The answers you get are only as good as the information you give!

 
thanks Dan. Nope the page is not fully loaded.

while the page is being rendered the first time when the servlet is called some text is flushed into the page which which force the page to reload thus calling the servlet again. In the servlet service method I have the logic to differentiate between the first and second calls. While it is called the first time I should get the cell size set it on the request. (note: I could get the client width and client height as a test.)

Flash image's size is set on the second run.

regards.
 

Whether it is the first or second load makes no difference. If you are not waiting for the page to fully load before using the code above, there is no way the returned values will be accurate.

Page layout is fluid - until everything has loaded, you cannot be sure of the final position of any element.

Suggest not calling the JS until then (you can use the body's onload event to test for this).

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
that was my whole point. Your code will not work in my case. Thats why I was asking whether the jsp/html DOM would know and is there a way to get to that? (I dont exactly know what these are but am just guessing, would be more than willing to learn more)
 
The answer is no, you can not retrive the size of the cell until it has been rendered, sorry. What you are wanting to achieve is not possible.

-kaht

Do the chickens have large talons?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top