René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

createElement with JavaScript in DHTML

This is tested on Internet Explorer only. Note, that it seems mandatory to append the child to the tBody collection of a table (at least in IE).
<html>
<head>

  <script language='javascript'>

    function addRow(a,b) {
      var r  = document.createElement('tr');
      var ca = document.createElement('td');
      var cb = document.createElement('td');
      var ta = document.createTextNode(a);
      var tb = document.createTextNode(b);
      var t  = document.getElementById('tbl');


      ca.appendChild(ta);
      cb.appendChild(tb);

      r.appendChild(ca);
      r.appendChild(cb);

      t.tBodies(0).appendChild(r);
    }

  </script>

</head>
<body>

   <form>
      Column A: <input type=text name=a>
  <br>Column B: <input type=text name=b>
  <br><input type=button value='add Row' onClick='javascript:addRow(a.value, b.value)'>

   </form>

   <table id=tbl>
     <tr><td>Column A</td><td>Column B</td></tr>
   </table>

</body>
</html>