[thelist] re: checkboxes, DOM, rows, etc

Fernando Gómez fgomez at criba.edu.ar
Thu Sep 19 18:08:01 CDT 2002

> I feel like we're so close I can TASTE it..arrrgh..

It's true, we're almost there!

> ----
> function addDoctor(name, city, id)
> {
>   var docTarget = window.frames['docs'].document;
>   var myTable = docTarget.getElementById('mydocs');
>   var myTableBody = docTarget.createElement("TBODY");
>   var newRow = docTarget.createElement("TR");
>   var newCell = docTarget.createElement("TD");
>   var newText = docTarget.createTextNode('someText');
>   newCell.appendChild(newText);
>   newRow.appendChild(newCell);
>   docTarget.getElementById(myTableBody).appendChild(newRow);
> }
> ----

> This essentially gives me an error on the last line - getElementById
> is NULL or not an object.

The line


should be


And these lines

   var myTable = docTarget.getElementById('mydocs');
   var myTableBody = docTarget.createElement("TBODY");

do not seem necessary now.

If you explicitly put the <tbody> element in your table, and attach an ID
attribute to it (as I showed in my previous message), then you only have to
worry about appending rows to that tbody, that's it.

(I've been learning to do this kind of tricks in the last couple of weeks,
that's why I think I understand your feelings. Here are a couple of links to
material that helped me see some things more clearly:

JavaScript: The Definitive Guide, 4th Edition
Chapter 17: The Document Object Model

Traversing an HTML Table with JavaScript and DOM Interfaces

And there's also some very good stuff here: http://www.xs4all.nl/~ppk/js/ )

But maybe we also need a break ;-)

Fernando Gómez

> I don't fully understand the table body thing anyway - maybe this is
> the problem. Should I just PUT a <tbody> tag in my table first? Do I
> need that..why doesn't it see the table body?

More information about the thelist mailing list