www.webdeveloper.com
Results 1 to 9 of 9

Thread: IE unknown runtime error

  1. #1
    Join Date
    Jan 2007
    Posts
    41

    IE unknown runtime error

    the following is working fine with firefox but not with IE(unknown runtime error), any idea??
    <html>
    <head>
    <title></title>
    <script language="javascript">
    function f()
    {
    document.getElementById("tbl").innerHTML = "<tr><td>col 1</td><td>col 2</td></tr>";
    }
    </script>
    </head>
    <body>
    <table>
    <thead>
    <tr>
    <th>Col 1</th>
    <th>Col 2</th>
    </tr>
    </thead>
    <tbody id="tbl">
    </tbody>
    </table>
    <input type="button" value="click" onclick="f();" />
    </body>
    </html>

  2. #2
    Join Date
    Sep 2004
    Posts
    294
    In a <table>, <tbody> is readonly. you have to build the entire tbody and then append it to the table

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    innerHTML is not a standard DOM method, and in this case it might not be the proper option. I would have used DOM
    Code:
    <script type="text/javascript">
    function f()
    {
    var root=document.getElementById("tbl");
    while(root.hasChildNodes()){
    root.removeChild(root.childNodes[0]);
    }
    var row=document.createElement('tr');
    var txt=['col 1','col 2'], i=0, t, cell;
    while(t=txt[i++]){
    cell=document.createElement('td');
    cell.appendChild(document.createTextNode(t));
    row.appendChild(cell)
    }
    root.appendChild(row);
    }
    </script>

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Or like this:
    Code:
    <script type="text/javascript">
    function addRow(tbodyID) {
    var oTB = document.getElementById(tbodyID);
    var oRow = oTB.insertRow(0);
    
    var oCell = oRow.insertCell(0);
    oCell.appendChild(document.createTextNode('col1'));
    
    oCell = oRow.insertCell(1);
    oCell.appendChild(document.createTextNode('col2'));
    }
    </script>
    
    </head>
    <body>
    <table>
    <thead>
    <tr>
    <th>Col 1</th>
    <th>Col 2</th>
    </tr>
    </thead>
    <tbody id="tbl">
    </tbody>
    </table>
    <input type="button" value="click" onclick="addRow('tbl');">
    
    </body>
    http://www.w3.org/TR/DOM-Level-2-HTML/html.html
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Jan 2007
    Posts
    41
    what if the rows and cell comes to me already rendered and i have to add it to a table??
    i receive string contains "<tr><td></td></tr><tr><td></td></tr>" , so i should embedded this text in a table or a tbody ?????

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    No, you will have to create a new table to add the string to.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Jan 2007
    Posts
    41
    how as innerHTML is not working ????

  8. #8
    Join Date
    Jan 2007
    Posts
    41
    the following is something typical to my case, it gives error with IE, now the above solutions require me to build the whole table where it is already built, and a string including the rows and cells should be appended, BUT HOOOOW ???
    <html>
    <head>
    <title></title>
    <script language="javascript">
    function f()
    {
    var txt = GetTableContent();//this function will return "<tr><td>text 1</td><td>text 1</td></tr>"
    document.getElementById("content").innerHTML = txt;
    }
    </script>

    </head>
    <body>

    <table>
    <thead>
    <tr>
    <th>Col 1</th>
    <th>Col 2</th>
    </tr>
    </thead>
    <tbody id="content></tbody>
    <tfoot>
    <tr>
    <td colspan="2"></td>
    </tr>
    </tfoot>
    </table>

    <input type="button" value="click" onclick="f();" />

    </body>
    </html>

  9. #9
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Ugly but works (note NO quotes around content)
    Code:
    <html>
    <head>
    <title></title>
    <script language="javascript">
    function f()
    {
    var txt = "<tr><td>text 1</td><td>text 1</td></tr>"
    var tbl=document.getElementById("root").innerHTML;
    var bits=tbl.split('content>');
    var newTable=bits[0]+'content>'+txt+bits[1];
    document.getElementById("root").innerHTML="";
    document.getElementById("root").innerHTML=newTable;
    }
    </script>
    
    </head>
    <body>
    
    <div id="root">
    <table border="1">
    <thead>
    <tr>
    <th>Col 1</th>
    <th>Col 2</th>
    </tr>
    </thead>
    <tbody id=content></tbody>
    <tfoot>
    <tr>
    <td colspan="2"></td>
    </tr>
    </tfoot>
    </table>
    </div>
    <input type="button" value="click" onclick="f();" />
    
    </body>
    </html>
    Consider rewriting GetTableContent() to give DOM object.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles