View Full Version : creating/dealing with an indeterminate number of table row objects?

08-17-2005, 04:51 AM
what i have is a page with a table full of form fields, and a button that, when i click it, should add another row into said table. i want the user to be able to add and delete as many as they want, and they all would have id's such as 'field1', 'field2', etc. the thing is, i can't seem to write a static function to handle this indeterminate amount of html objects. i have an example of the page here (http://www.coro36ink.com/e/table.html).

i thought perhaps i could use eval():

function modifyField(num) // num of the row to work with
eval('field'+num+'.someproperty = "somevalue";');

thus i could call it like modifyField(1) to have it work with document.field1, etc. however, this doesnt work. even when i hardcode the object in (a span with an id="field1"), i get the error "field1 is not an object", when i try to refer to it from within an eval().

is there ANY way to do this with javascript? i really dont want to have to put such a repetetive load on a server-side script...

08-17-2005, 03:39 PM
Why do you need eval?

x = "1";
element = document.getElementById('field'+x);

do whatever with element...

08-17-2005, 04:34 PM
ah, thank you. i'm retarded, i just needed to use getElementByID. (it bears mentioning that I've been away from javascript for a while, so I've forgotten a few things :o ) Thanks a bunch, though.