First, I don't suggest connecting events to your table with HTML onclick="something".
Second, I don't really understand what your are doing otherwise. Why aren't you using prototypes? I would think about how you want to logically separate out the elements of your application. Then divide them up into objects and figure out how to get the events to work together.
