PDA

View Full Version : Using innterHTML over DOM is messing up my class


snoodle
06-26-2007, 03:51 PM
I have a list "Class" (using methods (i.e. prototypes). It createst it's outer div using CreateElement, but the <table>, <tr>'s, <td>'s are all concatenated into one big string which ultimately gets stuck in the out div's innterHTML.

This is showing much better browser compatibility, and is faster than DOM/Creating each element down to the cell. However, either I don't understand something or it leads to some problems that try to break the OOP's structure...

DOM/Creating each element allows you to add members to existing elements. For example, a cell (i.e. <td></td>) can get a cell.row and cell.col, so when the onwhatevermouse method gets triggered, you can pass "this" as the argument and the hook function knows which cell it was clicked in (cell.col, cell.row).

However, I have learned through trying, that you (a) cannot add members to elements by inserting an unrecognizeable member name in the HTML string, and (b) if you fetch the cell, getting a refernce to the <td> element, you still can't just tack on members.

So, I attempted a couple of work arounds. I stuck the cell coordinates in the <td's> id field ("1,2"), to be parsed and utilized by the receiver functions, but the idea is that these hook functions need to call back into the methods of the parent object. The problem is, how do I get the object to the cell handling code. So, in the one element I do DOM/Create, "div", I added a member thats a reference to the object. Then each receiver function calls a function called CellToTblObj(cell), and it walks up the chain of nodes from the cell to the "div", so it can get the object reference. If I, in the receiver function do an alert(tblObj.oneOfMyOwnAddedMembers), it surely displays the appropriate value, so it appears it would work. Except for one problem... when I try to call tObj.method, it tells me "this.method is not an object, etc" and fails to call the method.

Why are the members ok but the methods wont work?

snoodle
06-26-2007, 08:20 PM
the reason for the method not being called was it was passing an invalid argument (namely, the old cell, which used to include members .col and .row. now i have to go this.id.getcol(cell) instead of this.col where this is the ref to the cell. sorry for my idiocy and waste of a thread.

snoodle
06-26-2007, 10:40 PM
i just spent 2 hours tracking down a bug caused by...

MyObj.prototype.Foo(x)
instead of
MyObj.prototype.Foo = function(x)

shoot me. take this thread and flush it down the toilet. i think i need some better javascript debugging tools.