I would like to know if it is easy or difficult to do the next thing:
I have a xhtml table, inside a form, where I have input values. I would like to have something similar to a spreadsheet, that when some input field is modified, some other fields are modified too. I'm using onkeyup(). But my problem is referencing the other fields because I haven't id attributes and the position of the nodes are different each time. Possibly this question is trivial, I'm new to Javascript, and any help or pointer in the right direction will be very useful.
But my problem is referencing the other fields because I haven't id attributes and the position of the nodes are different each time.
Those fields must have something unique (id), or something stable (position, DOM relationship) or something in common (same name, same class, same attribute...). It the last case, that something property must be univoque, that means it has to belong to all those elements, but only to them.
Now... giving them the same class looks the most convenient way. If so, tell me and I will give you a crossbrowser function getElementsByClassName() (as you might know, IE does not support the native getElementsByClassName() method)
in HTML tables, rows have .rowIndex, and cells have .cellIndex ...
combined with parentNode, row.cells[n], and table.rows[n], you can refer to any other cell without any special attribs.
i would also highly recommend using direct javascript bindings to define relationships when the above will not suffice, instead if DOM attribs like class, which will be much slower to access.
something like cell.related=[cell2,cell21,cell33];
Bookmarks