Solved

row.offsetHeight of a table row different in FireFox?

Posted on 2007-03-28
2
574 Views
Last Modified: 2013-11-19
In the following code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<style>
tr
{
    background-color:red;
    font-size:10pt;
}
</style>
<script language="javascript">
function onLoad()
{
    var div=document.getElementById("divCont");
   
    /*****************************/
    var NumOfRows = 1;
    /*****************************/
   
    var s = new Array();
    s.push("<table border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
   
    var row = document.getElementById("row_0");
    NumOfRows = (div.offsetHeight / row.offsetHeight);
   
    var s = new Array();
    s.push("<table border=1>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
}
</script>
</head>
<body onload="onLoad();">
<div id="divCont" style="position:absolute;left:10px;top:10px;width:400px;height:200px;border:solid 1px blue;">
</div>
</body>
</html>

I've create a table with the number of rows depending on the height of the "divCont".
In IE and Opera it works perfectly and the table keeps inside the div exactly, but in FireFox the rows overflow the div.

What can be happening and how can I fix it for FireFox?

Thanks
0
Comment
Question by:mak730
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 18812811
First of all, when you grab the height of the row, I would recommend getting the entire height of the table, especially since you add borders to the table. Thus, set an ID on the table and use getElementById() on that instead of row_0.

To fix for Firefox, make sure to set cellpadding and cellspacing in your second table to zero as well.
0
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 500 total points
ID: 18815438
No points necessary.........



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<style>
tr
{
    background-color:red;
    font-size:10pt;
}
</style>
<script language="javascript">
function onLoad()
{
    var div=document.getElementById("divCont");
   
    /*****************************/
    var NumOfRows = 1;
    /*****************************/
   
    var s = new Array();
    s.push("<table border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
   
    var row = document.getElementById("row_0");
    NumOfRows = parseInt (parseInt(div.offsetHeight) / parseInt(row.offsetHeight));
   
    var s = new Array();

    ////////// TAKE CARE HERE...

    s.push("<table border=1 border=1 cellspacing=0 cellpadding=0>");
    for(var i=0; i<NumOfRows; i++)
    {
      s.push("<tr id='row_" + i + "'>");
      s.push("  <td>Row " + i);
      s.push("  </td>");
      s.push("<tr>");
    }
    s.push("</table>");
    div.innerHTML = s.join("\n");
}
</script>
</head>
<body onload="onLoad();">
<div id="divCont" style="position:absolute;left:10px;top:10px; width:auto; height:200px; border:solid 1px blue;">
</div>
</body>
</html>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question